create empty disco result on error to fire advance stream features event

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java | 12 
src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java             | 15 
2 files changed, 26 insertions(+), 1 deletion(-)

Detailed changes

src/main/java/eu/siacs/conversations/entities/ServiceDiscoveryResult.java 🔗

@@ -86,6 +86,18 @@ public class ServiceDiscoveryResult {
 			}
 		}
 	}
+	
+	private ServiceDiscoveryResult() {
+		this.hash = "sha-1";
+		this.features = Collections.emptyList();
+		this.identities = Collections.emptyList();
+		this.ver = null;
+		this.forms = Collections.emptyList();
+	}
+
+	public static ServiceDiscoveryResult empty() {
+		return new ServiceDiscoveryResult();
+	}
 
 	public ServiceDiscoveryResult(Cursor cursor) throws JSONException {
 		this(

src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java 🔗

@@ -1205,8 +1205,21 @@ public class XmppConnection implements Runnable {
                 if (advancedStreamFeaturesLoaded && (jid.equals(Jid.of(account.getServer())) || jid.equals(account.getJid().asBareJid()))) {
                     enableAdvancedStreamFeatures();
                 }
-            } else {
+            } else if (packet.getType() == IqPacket.TYPE.ERROR) {
                 Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not query disco info for " + jid.toString());
+                final boolean serverOrAccount = jid.equals(Jid.of(account.getServer())) || jid.equals(account.getJid().asBareJid());
+                final boolean advancedStreamFeaturesLoaded;
+                if (serverOrAccount) {
+                    synchronized (XmppConnection.this.disco) {
+                        disco.put(jid, ServiceDiscoveryResult.empty());
+                        advancedStreamFeaturesLoaded = disco.containsKey(Jid.of(account.getServer())) && disco.containsKey(account.getJid().asBareJid());
+                    }
+                } else {
+                    advancedStreamFeaturesLoaded = false;
+                }
+                if (advancedStreamFeaturesLoaded) {
+                    enableAdvancedStreamFeatures();
+                }
             }
             if (packet.getType() != IqPacket.TYPE.TIMEOUT) {
                 if (mPendingServiceDiscoveries.decrementAndGet() == 0