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 {
|
|
|
|
|
|
2021-08-01 13:08:24 +00:00
|
|
|
private static ArrayList<ChatUser> chatUsers;
|
2021-05-15 19:16:01 +00:00
|
|
|
|
|
|
|
|
public static void initialize() {
|
2021-06-13 11:53:49 +00:00
|
|
|
chatUsers = new ArrayList<>();
|
2021-05-15 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addUser(ChatUser user) {
|
2021-07-27 16:46:58 +00:00
|
|
|
chatUsers.add(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void removeUser(ChatUser user) {
|
|
|
|
|
chatUsers.remove(user);
|
2021-05-15 19:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ChatUser getChatUser(UUID uuid) {
|
|
|
|
|
for(ChatUser user : chatUsers) {
|
2021-07-30 01:16:41 +00:00
|
|
|
if(uuid.equals(user.getUuid())) {
|
2021-05-15 19:16:01 +00:00
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-04 13:07:16 +00:00
|
|
|
return 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
|
|
|
|
|
|
|
|
protected static List<ChatUser> getChatUsers() {
|
|
|
|
|
return Collections.unmodifiableList(chatUsers);
|
|
|
|
|
}
|
2021-05-15 19:16:01 +00:00
|
|
|
}
|