--- a/src/main/java/de/unixwork/im/Xmpp.java Thu Dec 26 12:29:05 2024 +0100 +++ b/src/main/java/de/unixwork/im/Xmpp.java Thu Dec 26 12:53:02 2024 +0100 @@ -24,10 +24,12 @@ import org.jivesoftware.smack.filter.MessageWithBodiesFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.MessageBuilder; +import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smack.roster.RosterEntry; import org.jivesoftware.smack.tcp.XMPPTCPConnection; import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; +import org.jxmpp.jid.Jid; import org.jxmpp.stringprep.XmppStringprepException; public class Xmpp extends Thread { @@ -46,7 +48,6 @@ config = xmppConfig; otr = new OTR(this); otrSM = new OtrSessionManagerImpl(otr); - } public OTR getOTR() { @@ -133,7 +134,15 @@ String body = ((Message)stanza).getBody(); App.getInstance().dispatchMessage(jid, body, true); } - }), MessageWithBodiesFilter.INSTANCE); + }), MessageWithBodiesFilter.INSTANCE); + connection.addAsyncStanzaListener(stanza -> { + if (stanza instanceof Presence) { + Presence presence = (Presence) stanza; + Jid from = presence.getFrom(); + Presence.Type type = presence.getType(); + App.getInstance().handlePresence(from, type); + } + }, stanza -> stanza instanceof Presence); List<RosterEntry> roster = getRosterItems(); if(roster != null) { App.getInstance().setContacts(roster);