Chat/api/src/main/java/com/alttd/chat/managers/ChatUserManager.java

43 lines
1.1 KiB
Java
Raw Normal View History

2021-06-02 17:55:55 +00:00
package com.alttd.chat.managers;
2021-05-15 19:16:01 +00:00
2021-07-27 16:46:58 +00:00
import com.alttd.chat.database.Queries;
2021-06-02 17:55:55 +00:00
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.Mail;
2021-05-15 19:16:01 +00:00
import java.util.*;
2021-05-15 22:28:47 +00:00
import java.util.stream.Collectors;
2021-05-15 19:16:01 +00:00
public final class ChatUserManager {
private static Map<UUID, ChatUser> chatUsers;
2021-05-15 19:16:01 +00:00
public static void initialize() {
chatUsers = new TreeMap<>();
2021-05-15 19:16:01 +00:00
}
public static void addUser(ChatUser user) {
chatUsers.put(user.getUuid(), user);
2021-07-27 16:46:58 +00:00
}
public static void removeUser(ChatUser user) {
chatUsers.remove(user);
2021-05-15 19:16:01 +00:00
}
/**
* Get the ChatUser for this player or query the database to read the data.
*
* @param uuid the player who's ChatUser you'd like to get
* @return The ChatUser loaded from database or null if it's not existing.
*/
2021-05-15 19:16:01 +00:00
public static ChatUser getChatUser(UUID uuid) {
return chatUsers.computeIfAbsent(uuid, k -> Queries.loadChatUser(uuid));
2021-05-15 19:16:01 +00:00
}
2021-05-15 22:28:47 +00:00
public List<Mail> getUnReadMail(ChatUser user) {
return user.getMails().stream()
.filter(Mail::isUnRead)
.collect(Collectors.toList());
}
2021-05-15 19:16:01 +00:00
}