RealTime (update chat list)
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
package org.to.telegramfinalproject.Client;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.to.telegramfinalproject.Models.ChatEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
// method for save data from server response
|
||||
public class Session {
|
||||
public static JSONObject currentUser;
|
||||
public static List<ChatEntry> chatList;
|
||||
public static List<ChatEntry> chatList = new ArrayList<>();
|
||||
public static volatile boolean forceRefreshChatList = false;
|
||||
|
||||
|
||||
public static String getUserUUID() {
|
||||
if (currentUser.has("uuid")) return currentUser.getString("uuid");
|
||||
@@ -18,4 +23,26 @@ public class Session {
|
||||
throw new RuntimeException("❌ No UUID found in currentUser!");
|
||||
}
|
||||
|
||||
public static void updateChatList(JSONArray chatArray) {
|
||||
chatList.clear();
|
||||
for (int i = 0; i < chatArray.length(); i++) {
|
||||
JSONObject obj = chatArray.getJSONObject(i);
|
||||
ChatEntry entry = new ChatEntry(
|
||||
UUID.fromString(obj.getString("internal_id")),
|
||||
obj.optString("id", ""), // displayId
|
||||
obj.optString("name", ""), // name
|
||||
obj.optString("image_url", ""),
|
||||
obj.getString("type"),
|
||||
null, // last message time (if needed, parse it)
|
||||
obj.optBoolean("is_owner", false),
|
||||
obj.optBoolean("is_admin", false)
|
||||
);
|
||||
entry.setPermissions(obj.optJSONObject("permissions")); // اگر permissions وجود داره
|
||||
chatList.add(entry);
|
||||
}
|
||||
}
|
||||
public static List<ChatEntry> getChatList() {
|
||||
return chatList;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user