update contact list
This commit is contained in:
@@ -2959,7 +2959,7 @@ public class ActionHandler {
|
||||
}
|
||||
case "2" -> {
|
||||
addContact(chat.getId());
|
||||
refreshChatList();
|
||||
refreshContactList();
|
||||
}
|
||||
default -> System.out.println("Back...");
|
||||
}
|
||||
@@ -3213,6 +3213,59 @@ public class ActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshContactList() {
|
||||
JSONObject req = new JSONObject();
|
||||
req.put("action", "get_contact_list");
|
||||
req.put("user_id", Session.currentUser.getString("user_id"));
|
||||
out.println(req.toString());
|
||||
|
||||
try {
|
||||
JSONObject response = TelegramClient.responseQueue.take();
|
||||
|
||||
if (response != null && response.getString("status").equals("success")) {
|
||||
if (response.has("data") && !response.isNull("data")) {
|
||||
JSONObject data = response.getJSONObject("data");
|
||||
|
||||
if (!data.has("contact_list") || data.isNull("contact_list")) {
|
||||
System.out.println("❌ contact_list not found in response data.");
|
||||
return;
|
||||
}
|
||||
|
||||
JSONArray contactListJson = data.getJSONArray("contact_list");
|
||||
List<ContactEntry> contactList = new ArrayList<>();
|
||||
|
||||
for (Object obj : contactListJson) {
|
||||
JSONObject c = (JSONObject) obj;
|
||||
|
||||
ContactEntry entry = new ContactEntry(
|
||||
UUID.fromString(c.getString("contact_id")),
|
||||
c.getString("user_id"),
|
||||
c.getString("profile_name"),
|
||||
c.optString("image_url", ""),
|
||||
c.optBoolean("is_blocked", false)
|
||||
);
|
||||
|
||||
contactList.add(entry);
|
||||
}
|
||||
|
||||
Session.contactEntries = contactList;
|
||||
System.out.println("✅ Contact list updated. Total: " + contactList.size());
|
||||
|
||||
} else {
|
||||
System.out.println("⚠️ Response has no data object.");
|
||||
}
|
||||
} else {
|
||||
if (response.has("message") && !response.isNull("message")) {
|
||||
System.out.println("❌ Failed to refresh contact list: " + response.getString("message"));
|
||||
} else {
|
||||
System.out.println("❌ Failed to refresh contact list.");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ Error during refreshContactList: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -79,19 +79,19 @@ public class IncomingMessageListener implements Runnable {
|
||||
"update_group_or_channel", "chat_deleted",
|
||||
"blocked_by_user", "unblocked_by_user", "message_seen",
|
||||
"removed_from_group", "removed_from_channel",
|
||||
"became_admin", "removed_admin", "ownership_transferred","admin_permissions_updated" -> true;
|
||||
"became_admin", "removed_admin", "ownership_transferred","admin_permissions_updated","created_private_chat" -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
void handleRealTimeEvent(JSONObject response) throws IOException {
|
||||
String action = response.getString("action");
|
||||
JSONObject msg = response.getJSONObject("data");
|
||||
JSONObject msg = response.has("data") ? response.getJSONObject("data") : new JSONObject();
|
||||
|
||||
|
||||
switch (action) {
|
||||
case "added_to_group", "added_to_channel",
|
||||
"removed_from_group", "removed_from_channel", "chat_deleted" -> {
|
||||
"removed_from_group", "removed_from_channel", "chat_deleted","created_private_chat" -> {
|
||||
System.out.println("🔄 Chat list changed. Updating...");
|
||||
Session.forceRefreshChatList = true;
|
||||
System.out.println("🧪 Calling requestChatList() after being added");
|
||||
@@ -135,10 +135,6 @@ public class IncomingMessageListener implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
default -> displayRealTimeMessage(action, msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ public class Session {
|
||||
public static String currentChatId = null;
|
||||
public static ChatEntry currentChatEntry = null;
|
||||
public static List<ContactEntry> contactEntries = new ArrayList<>();
|
||||
|
||||
|
||||
public static boolean inContactListMenu = false;
|
||||
|
||||
|
||||
public static String getUserUUID() {
|
||||
|
||||
Reference in New Issue
Block a user