aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2016-01-17 17:11:00 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2016-01-24 17:46:08 -0500
commitae84ff2f0c01be832075d16556db2136c1b5ac55 (patch)
treea5da8aaaf3806df2ee2067fd4401b89a3a47aae7 /src/main
parent000f59d614d07ac573c1159ea964ebfee6ecbef5 (diff)
Do disco for caps hashes we have never seen
Then cache it
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/eu/siacs/conversations/parser/PresenceParser.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java
index 88631a91..da7a8ce6 100644
--- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java
@@ -14,9 +14,11 @@ 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
@@ -161,7 +163,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()) {
@@ -180,11 +182,30 @@ public class PresenceParser extends AbstractParser implements
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"));
}
- contact.updatePresence(presence, new Presence(packet.findChild("show"), disco));
+
+ 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");