diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/xmpp/XmppConnection.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index a279308e0..a6fe3756a 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -31,6 +31,7 @@ import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; @@ -71,6 +72,7 @@ import de.pixart.messenger.entities.ServiceDiscoveryResult; import de.pixart.messenger.generator.IqGenerator; import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.services.MemorizingTrustManager; +import de.pixart.messenger.services.MessageArchiveService; import de.pixart.messenger.services.NotificationService; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.ui.EditAccountActivity; @@ -211,8 +213,7 @@ public class XmppConnection implements Runnable { protected void changeStatus(final Account.State nextStatus) { synchronized (this) { - this.mThread = Thread.currentThread(); - if (this.mThread.isInterrupted()) { + if (Thread.currentThread().isInterrupted()) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": not changing status to " + nextStatus + " because thread was interrupted"); return; } @@ -503,7 +504,8 @@ public class XmppConnection implements Runnable { @Override public void run() { synchronized (this) { - if (Thread.currentThread().isInterrupted()) { + this.mThread = Thread.currentThread(); + if (this.mThread.isInterrupted()) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": aborting connect because thread was interrupted"); return; } @@ -601,6 +603,7 @@ public class XmppConnection implements Runnable { final String h = resumed.getAttribute("h"); try { ArrayList<AbstractAcknowledgeableStanza> failedStanzas = new ArrayList<>(); + final boolean acknowledgedMessages; synchronized (this.mStanzaQueue) { final int serverCount = Integer.parseInt(h); if (serverCount < stanzasSent) { @@ -610,12 +613,15 @@ public class XmppConnection implements Runnable { } else { Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": session resumed"); } - acknowledgeStanzaUpTo(serverCount); + acknowledgedMessages = acknowledgeStanzaUpTo(serverCount); for (int i = 0; i < this.mStanzaQueue.size(); ++i) { failedStanzas.add(mStanzaQueue.valueAt(i)); } mStanzaQueue.clear(); } + if (acknowledgedMessages) { + mXmppConnectionService.updateConversationUi(); + } Log.d(Config.LOGTAG, "resending " + failedStanzas.size() + " stanzas"); for (AbstractAcknowledgeableStanza packet : failedStanzas) { if (packet instanceof MessagePacket) { @@ -656,9 +662,13 @@ public class XmppConnection implements Runnable { final Element ack = tagReader.readElement(nextTag); lastPacketReceived = SystemClock.elapsedRealtime(); try { + final boolean acknowledgedMessages; synchronized (this.mStanzaQueue) { final int serverSequence = Integer.parseInt(ack.getAttribute("h")); - acknowledgeStanzaUpTo(serverSequence); + acknowledgedMessages = acknowledgeStanzaUpTo(serverSequence); + } + if (acknowledgedMessages) { + mXmppConnectionService.updateConversationUi(); } } catch (NumberFormatException | NullPointerException e) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": server send ack without sequence number"); @@ -668,8 +678,12 @@ public class XmppConnection implements Runnable { try { final int serverCount = Integer.parseInt(failed.getAttribute("h")); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": resumption failed but server acknowledged stanza #" + serverCount); + final boolean acknowledgedMessages; synchronized (this.mStanzaQueue) { - acknowledgeStanzaUpTo(serverCount); + acknowledgedMessages = acknowledgeStanzaUpTo(serverCount); + } + if (acknowledgedMessages) { + mXmppConnectionService.updateConversationUi(); } } catch (NumberFormatException | NullPointerException e) { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": resumption failed"); @@ -690,10 +704,11 @@ public class XmppConnection implements Runnable { } } - private void acknowledgeStanzaUpTo(int serverCount) { + private boolean acknowledgeStanzaUpTo(int serverCount) { if (serverCount > stanzasSent) { Log.e(Config.LOGTAG, "server acknowledged more stanzas than we sent. serverCount=" + serverCount + ", ourCount=" + stanzasSent); } + boolean acknowledgedMessages = false; for (int i = 0; i < mStanzaQueue.size(); ++i) { if (serverCount >= mStanzaQueue.keyAt(i)) { if (Config.EXTENDED_SM_LOGGING) { @@ -702,12 +717,13 @@ public class XmppConnection implements Runnable { AbstractAcknowledgeableStanza stanza = mStanzaQueue.valueAt(i); if (stanza instanceof MessagePacket && acknowledgedListener != null) { MessagePacket packet = (MessagePacket) stanza; - acknowledgedListener.onMessageAcknowledged(account, packet.getId()); + acknowledgedMessages |= acknowledgedListener.onMessageAcknowledged(account, packet.getId()); } mStanzaQueue.removeAt(i); i--; } } + return acknowledgedMessages; } private @NonNull @@ -1574,6 +1590,7 @@ public class XmppConnection implements Runnable { for (final Entry<Jid, ServiceDiscoveryResult> cursor : disco.entrySet()) { final ServiceDiscoveryResult value = cursor.getValue(); if (value.getFeatures().contains("http://jabber.org/protocol/muc") + && value.hasIdentity("conference", "text") && !value.getFeatures().contains("jabber:iq:gateway") && !value.hasIdentity("conference", "irc")) { servers.add(cursor.getKey().toString()); @@ -1820,13 +1837,12 @@ public class XmppConnection implements Runnable { } public boolean mam() { - return hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM) - || hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM_LEGACY); + return MessageArchiveService.Version.has(getAccountFeatures()); } - public boolean mamLegacy() { - return !hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM) - && hasDiscoFeature(account.getJid().asBareJid(), Namespace.MAM_LEGACY); + public List<String> getAccountFeatures() { + ServiceDiscoveryResult result = connection.disco.get(account.getJid().asBareJid()); + return result == null ? Collections.emptyList() : result.getFeatures(); } public boolean push() { |