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

changeset 2
94c6a715fa44
parent 1
42d0d099492b
child 4
856befba7674
equal deleted inserted replaced
1:42d0d099492b 2:94c6a715fa44
22 import org.jivesoftware.smack.SmackException; 22 import org.jivesoftware.smack.SmackException;
23 import org.jivesoftware.smack.XMPPException; 23 import org.jivesoftware.smack.XMPPException;
24 import org.jivesoftware.smack.filter.MessageWithBodiesFilter; 24 import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
25 import org.jivesoftware.smack.packet.Message; 25 import org.jivesoftware.smack.packet.Message;
26 import org.jivesoftware.smack.packet.MessageBuilder; 26 import org.jivesoftware.smack.packet.MessageBuilder;
27 import org.jivesoftware.smack.packet.Presence;
27 import org.jivesoftware.smack.roster.Roster; 28 import org.jivesoftware.smack.roster.Roster;
28 import org.jivesoftware.smack.roster.RosterEntry; 29 import org.jivesoftware.smack.roster.RosterEntry;
29 import org.jivesoftware.smack.tcp.XMPPTCPConnection; 30 import org.jivesoftware.smack.tcp.XMPPTCPConnection;
30 import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; 31 import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
32 import org.jxmpp.jid.Jid;
31 import org.jxmpp.stringprep.XmppStringprepException; 33 import org.jxmpp.stringprep.XmppStringprepException;
32 34
33 public class Xmpp extends Thread { 35 public class Xmpp extends Thread {
34 private final XMPPTCPConnectionConfiguration config; 36 private final XMPPTCPConnectionConfiguration config;
35 37
44 46
45 public Xmpp(XMPPTCPConnectionConfiguration xmppConfig) { 47 public Xmpp(XMPPTCPConnectionConfiguration xmppConfig) {
46 config = xmppConfig; 48 config = xmppConfig;
47 otr = new OTR(this); 49 otr = new OTR(this);
48 otrSM = new OtrSessionManagerImpl(otr); 50 otrSM = new OtrSessionManagerImpl(otr);
49
50 } 51 }
51 52
52 public OTR getOTR() { 53 public OTR getOTR() {
53 return otr; 54 return otr;
54 } 55 }
131 var jid = stanza.getFrom(); 132 var jid = stanza.getFrom();
132 if(jid != null) { 133 if(jid != null) {
133 String body = ((Message)stanza).getBody(); 134 String body = ((Message)stanza).getBody();
134 App.getInstance().dispatchMessage(jid, body, true); 135 App.getInstance().dispatchMessage(jid, body, true);
135 } 136 }
136 }), MessageWithBodiesFilter.INSTANCE); 137 }), MessageWithBodiesFilter.INSTANCE);
138 connection.addAsyncStanzaListener(stanza -> {
139 if (stanza instanceof Presence) {
140 Presence presence = (Presence) stanza;
141 Jid from = presence.getFrom();
142 Presence.Type type = presence.getType();
143 App.getInstance().handlePresence(from, type);
144 }
145 }, stanza -> stanza instanceof Presence);
137 List<RosterEntry> roster = getRosterItems(); 146 List<RosterEntry> roster = getRosterItems();
138 if(roster != null) { 147 if(roster != null) {
139 App.getInstance().setContacts(roster); 148 App.getInstance().setContacts(roster);
140 } 149 }
141 150

mercurial