src/main/java/de/unixwork/im/App.java

changeset 2
94c6a715fa44
parent 0
f3095cda599e
child 3
25a32e2dfde5
--- a/src/main/java/de/unixwork/im/App.java	Thu Dec 26 12:29:05 2024 +0100
+++ b/src/main/java/de/unixwork/im/App.java	Thu Dec 26 12:53:02 2024 +0100
@@ -4,8 +4,10 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import org.jivesoftware.smack.packet.Presence;
 import org.jivesoftware.smack.roster.RosterEntry;
 import org.jxmpp.jid.Jid;
+import org.jxmpp.jid.parts.Resourcepart;
 
 public class App {
     
@@ -13,6 +15,7 @@
     
     private final ContactListFrame contactListFrame;
     private final Map<String, ConversationFrame> conversations;
+    private final Map<String, PresenceInfo> presence = new HashMap<>(32);
 
     private final Xmpp xmpp;
     
@@ -81,4 +84,31 @@
     public void runOnUiThread(Runnable action) {
         SwingUtilities.invokeLater(action);
     }
+
+    public String getStatusForXID(String xid) {
+        PresenceInfo ps = presence.get(xid);
+        if(ps == null) {
+            return "<offline> ";
+        }
+        return ps.getOnlineStatus();
+    }
+    
+    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
+        }
+    }
 }

mercurial