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
|
|
|
|
2021-08-18 22:59:37 +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 {
|
|
|
|
|
|
2022-01-27 20:05:50 +00:00
|
|
|
private static Map<UUID, ChatUser> chatUsers;
|
2021-05-15 19:16:01 +00:00
|
|
|
|
|
|
|
|
public static void initialize() {
|
2022-01-27 20:05:50 +00:00
|
|
|
chatUsers = new TreeMap<>();
|
2021-05-15 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addUser(ChatUser user) {
|
2022-01-27 20:05:50 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-01-27 20:05:50 +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) {
|
2022-01-27 20:05:50 +00:00
|
|
|
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-08-04 13:07:16 +00:00
|
|
|
|
2021-05-15 19:16:01 +00:00
|
|
|
}
|