update refreshChatList
This commit is contained in:
@@ -268,34 +268,45 @@ public class ActionHandler {
|
|||||||
if (response.has("data") && !response.isNull("data")) {
|
if (response.has("data") && !response.isNull("data")) {
|
||||||
JSONObject data = response.getJSONObject("data");
|
JSONObject data = response.getJSONObject("data");
|
||||||
|
|
||||||
//is chat list available
|
if ((!data.has("active_chat_list") || data.isNull("active_chat_list")) &&
|
||||||
if (!data.has("chat_list") || data.isNull("chat_list")) {
|
(!data.has("archived_chat_list") || data.isNull("archived_chat_list"))) {
|
||||||
System.out.println("❌ chat_list not found in response data.");
|
System.out.println("❌ No chat list found in response data.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray chatListJson = data.getJSONArray("chat_list");
|
List<ChatEntry> activeChats = new ArrayList<>();
|
||||||
List<ChatEntry> chatList = new ArrayList<>();
|
List<ChatEntry> archivedChats = new ArrayList<>();
|
||||||
|
|
||||||
for (Object obj : chatListJson) {
|
// 📁 Parse active chat list
|
||||||
|
if (data.has("active_chat_list") && !data.isNull("active_chat_list")) {
|
||||||
|
JSONArray activeJson = data.getJSONArray("active_chat_list");
|
||||||
|
for (Object obj : activeJson) {
|
||||||
JSONObject chat = (JSONObject) obj;
|
JSONObject chat = (JSONObject) obj;
|
||||||
|
ChatEntry entry = parseChatEntry(chat);
|
||||||
ChatEntry entry = new ChatEntry(
|
activeChats.add(entry);
|
||||||
UUID.fromString(chat.getString("internal_id")),
|
}
|
||||||
chat.getString("id"),
|
|
||||||
chat.getString("name"),
|
|
||||||
chat.optString("image_url", ""),
|
|
||||||
chat.getString("type"),
|
|
||||||
chat.isNull("last_message_time") ? null : LocalDateTime.parse(chat.getString("last_message_time")),
|
|
||||||
chat.optBoolean("is_owner", false),
|
|
||||||
chat.optBoolean("is_admin", false)
|
|
||||||
);
|
|
||||||
|
|
||||||
chatList.add(entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Session.chatList = chatList;
|
// 📁 Parse archived chat list
|
||||||
System.out.println("✅ Chat list updated. Total: " + chatList.size());
|
if (data.has("archived_chat_list") && !data.isNull("archived_chat_list")) {
|
||||||
|
JSONArray archivedJson = data.getJSONArray("archived_chat_list");
|
||||||
|
for (Object obj : archivedJson) {
|
||||||
|
JSONObject chat = (JSONObject) obj;
|
||||||
|
ChatEntry entry = parseChatEntry(chat);
|
||||||
|
archivedChats.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Session.chatList = new ArrayList<>();
|
||||||
|
Session.chatList.addAll(activeChats);
|
||||||
|
Session.chatList.addAll(archivedChats);
|
||||||
|
|
||||||
|
Session.activeChats = activeChats;
|
||||||
|
Session.archivedChats = archivedChats;
|
||||||
|
|
||||||
|
System.out.println("✅ Chat list updated.");
|
||||||
|
System.out.println("📂 Active Chats: " + activeChats.size());
|
||||||
|
System.out.println("📁 Archived Chats: " + archivedChats.size());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("⚠️ Response has no data object.");
|
System.out.println("⚠️ Response has no data object.");
|
||||||
}
|
}
|
||||||
@@ -312,6 +323,26 @@ public class ActionHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ChatEntry parseChatEntry(JSONObject chat) {
|
||||||
|
ChatEntry entry = new ChatEntry(
|
||||||
|
UUID.fromString(chat.getString("internal_id")),
|
||||||
|
chat.getString("id"),
|
||||||
|
chat.getString("name"),
|
||||||
|
chat.optString("image_url", ""),
|
||||||
|
chat.getString("type"),
|
||||||
|
chat.isNull("last_message_time") ? null : LocalDateTime.parse(chat.getString("last_message_time")),
|
||||||
|
chat.optBoolean("is_owner", false),
|
||||||
|
chat.optBoolean("is_admin", false)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (chat.has("other_user_id") && !chat.isNull("other_user_id")) {
|
||||||
|
entry.setOtherUserId(UUID.fromString(chat.getString("other_user_id")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void createGroup() {
|
public void createGroup() {
|
||||||
String groupId = null;
|
String groupId = null;
|
||||||
|
|||||||
@@ -397,6 +397,8 @@ public class MessageDatabase {
|
|||||||
try (Connection conn = ConnectionDb.connect();
|
try (Connection conn = ConnectionDb.connect();
|
||||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
stmt.setObject(1, groupId);
|
stmt.setObject(1, groupId);
|
||||||
|
stmt.setObject(2, userId);
|
||||||
|
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
result.add(extractMessage(rs));
|
result.add(extractMessage(rs));
|
||||||
@@ -431,7 +433,7 @@ public class MessageDatabase {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
public static List<Message> channelChatHistory(UUID channelId,UUID userId) {
|
public static List<Message> channelChatHistory(UUID channelId, UUID userId) {
|
||||||
List<Message> result = new ArrayList<>();
|
List<Message> result = new ArrayList<>();
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT * FROM messages
|
SELECT * FROM messages
|
||||||
@@ -446,7 +448,10 @@ public class MessageDatabase {
|
|||||||
|
|
||||||
try (Connection conn = ConnectionDb.connect();
|
try (Connection conn = ConnectionDb.connect();
|
||||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
|
||||||
stmt.setObject(1, channelId);
|
stmt.setObject(1, channelId);
|
||||||
|
stmt.setObject(2, userId);
|
||||||
|
|
||||||
ResultSet rs = stmt.executeQuery();
|
ResultSet rs = stmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
result.add(extractMessage(rs));
|
result.add(extractMessage(rs));
|
||||||
|
|||||||
Reference in New Issue
Block a user