--- a/src/main/java/de/unixwork/im/App.java Thu Dec 26 12:53:02 2024 +0100 +++ b/src/main/java/de/unixwork/im/App.java Thu Dec 26 17:19:15 2024 +0100 @@ -46,12 +46,14 @@ // Method to open a conversation window public void openConversation(String xid) { SwingUtilities.invokeLater(() -> { - if (!conversations.containsKey(xid)) { - ConversationFrame conversationFrame = new ConversationFrame(xid); + ConversationFrame conversationFrame = conversations.get(xid); + if (conversationFrame == null) { + conversationFrame = new ConversationFrame(xid); conversations.put(xid, conversationFrame); conversationFrame.setVisible(true); } else { - conversations.get(xid).toFront(); + conversationFrame.setVisible(true); + conversationFrame.toFront(); } }); } @@ -80,13 +82,12 @@ }); } - // Method to perform actions in the GUI thread from other threads - public void runOnUiThread(Runnable action) { - SwingUtilities.invokeLater(action); + public PresenceInfo getPresenceForXID(String xid) { + return presence.get(xid); } - + public String getStatusForXID(String xid) { - PresenceInfo ps = presence.get(xid); + PresenceInfo ps = getPresenceForXID(xid); if(ps == null) { return "<offline> "; } @@ -96,19 +97,27 @@ void handlePresence(Jid from, Presence.Type type) { System.out.println("presence from: " + from.toString() + " type: " + type.toString()); - String xid = from.asBareJid().toString(); - PresenceInfo ps = presence.get(xid); - if(ps == null) { - ps = new PresenceInfo(); - presence.put(xid, ps); - } - - // update presence - Resourcepart resource = from.getResourceOrNull(); - if(resource != null) { - ps.setStatus(resource.toString(), type); - } else { - // TODO - } + SwingUtilities.invokeLater(() -> { + String xid = from.asBareJid().toString(); + PresenceInfo ps = presence.get(xid); + if(ps == null) { + ps = new PresenceInfo(); + presence.put(xid, ps); + } + + // update presence + Resourcepart resource = from.getResourceOrNull(); + if(resource != null) { + ps.setStatus(resource.toString(), type); + } else { + // TODO + } + + contactListFrame.reload(); + ConversationFrame conversation = conversations.get(xid); + if(conversation != null) { + conversation.updatePresence(ps); + } + }); } }