diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-02-02 18:19:26 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-02-02 18:19:26 +0100 |
commit | 4a1a59f0c8ce99fd42909fb472179daec5065625 (patch) | |
tree | c7946ed356111082e1e296a933b30a71f8b25314 /src/main/java/eu/siacs/conversations/parser | |
parent | 01bad127084cdfc623c57be18e123ef8ff6655b0 (diff) | |
parent | ae84ff2f0c01be832075d16556db2136c1b5ac55 (diff) |
Merge branch 'disco-caps' of https://github.com/singpolyma/Conversations into singpolyma-disco-caps
Diffstat (limited to 'src/main/java/eu/siacs/conversations/parser')
-rw-r--r-- | src/main/java/eu/siacs/conversations/parser/PresenceParser.java | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index a07b42a9..5a25b283 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -13,13 +13,16 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions; -import eu.siacs.conversations.entities.Presences; +import eu.siacs.conversations.entities.Presence; +import eu.siacs.conversations.entities.ServiceDiscoveryResult; import eu.siacs.conversations.generator.PresenceGenerator; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.xml.Element; +import eu.siacs.conversations.xmpp.OnIqPacketReceived; import eu.siacs.conversations.xmpp.OnPresencePacketReceived; import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.pep.Avatar; +import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; public class PresenceParser extends AbstractParser implements @@ -167,7 +170,7 @@ public class PresenceParser extends AbstractParser implements final String type = packet.getAttribute("type"); final Contact contact = account.getRoster().getContact(from); if (type == null) { - String presence = from.isBareJid() ? "" : from.getResourcepart(); + final String presence = from.isBareJid() ? "" : from.getResourcepart(); contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick")); Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); if (avatar != null && !contact.isSelf()) { @@ -183,7 +186,34 @@ public class PresenceParser extends AbstractParser implements } } int sizeBefore = contact.getPresences().size(); - contact.updatePresence(presence, Presences.parseShow(packet.findChild("show"))); + + ServiceDiscoveryResult disco = null; + Element caps = packet.findChild("c", "http://jabber.org/protocol/caps"); + + if (caps != null) { + disco = mXmppConnectionService.databaseBackend. + findDiscoveryResult(caps.getAttribute("hash"), caps.getAttribute("ver")); + } + + if (disco != null || caps == null) { + contact.updatePresence(presence, new Presence(packet.findChild("show"), disco)); + } else { + IqPacket request = new IqPacket(IqPacket.TYPE.GET); + request.setTo(from); + request.query("http://jabber.org/protocol/disco#info"); + + mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket discoPacket) { + if (discoPacket.getType() == IqPacket.TYPE.RESULT) { + ServiceDiscoveryResult disco = new ServiceDiscoveryResult(discoPacket); + contact.updatePresence(presence, new Presence(packet.findChild("show"), disco)); + mXmppConnectionService.databaseBackend.insertDiscoveryResult(disco); + } + } + }); + } + PgpEngine pgp = mXmppConnectionService.getPgpEngine(); Element x = packet.findChild("x", "jabber:x:signed"); if (pgp != null && x != null) { |