diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-03-23 23:39:00 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-03-23 23:39:00 +0100 |
commit | 52a2efe0a87d6422060e78e0ca7df38c2affd2f2 (patch) | |
tree | 9e7a4cfb669f29b7b4d10bd987d595b9c0ab66ab /src/main/java/de/pixart/messenger | |
parent | 95ef8fd216d31aabd089649161ac699d06f3f8cd (diff) |
experimental: wait for SM catchup before triggering notifications
wait for a first SM ACK before calculating if we need to trigger any
notifications
might have to be changed to an XEP-0199 ping later on. for now sending
<r/> after resume seems to work outfine
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r-- | src/main/java/de/pixart/messenger/parser/MessageParser.java | 8 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/xmpp/XmppConnection.java | 21 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/parser/MessageParser.java b/src/main/java/de/pixart/messenger/parser/MessageParser.java index baa3b4d79..6965dfed5 100644 --- a/src/main/java/de/pixart/messenger/parser/MessageParser.java +++ b/src/main/java/de/pixart/messenger/parser/MessageParser.java @@ -595,10 +595,14 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) { manager.createNewDownloadConnection(message); } else if (notify) { - if (query == null) { - mXmppConnectionService.getNotificationService().push(message); + if (query != null && query.isCatchup()) { + mXmppConnectionService.getNotificationService().pushFromBacklog(message); + } else if (account.getXmppConnection().isWaitingForSmCatchup()) { + account.getXmppConnection().incrementSmCatchupMessageCounter(); } else if (query.isCatchup()) { // mam catchup mXmppConnectionService.getNotificationService().pushFromBacklog(message); + } else { + mXmppConnectionService.getNotificationService().push(message); } } } else if (!packet.hasChild("body")) { //no body diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 48d4c631a..eedc8219d 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -122,6 +122,8 @@ public class XmppConnection implements Runnable { private long lastDiscoStarted = 0; private AtomicInteger mPendingServiceDiscoveries = new AtomicInteger(0); private AtomicBoolean mWaitForDisco = new AtomicBoolean(true); + private AtomicBoolean mWaitingForSmCatchup = new AtomicBoolean(false); + private AtomicInteger mSmCatchupMessageCounter = new AtomicInteger(0); private boolean mInteractive = false; private int attempt = 0; public static String errorMessage = null; @@ -249,9 +251,18 @@ public class XmppConnection implements Runnable { this.lastConnect = SystemClock.elapsedRealtime(); this.lastPingSent = SystemClock.elapsedRealtime(); this.lastDiscoStarted = Long.MAX_VALUE; + this.mWaitingForSmCatchup.set(false); this.changeStatus(Account.State.CONNECTING); } + public boolean isWaitingForSmCatchup() { + return mWaitingForSmCatchup.get(); + } + + public void incrementSmCatchupMessageCounter() { + this.mSmCatchupMessageCounter.incrementAndGet(); + } + protected void connect() { if (mXmppConnectionService.areMessagesInitialized()) { mXmppConnectionService.resetSendingToWaiting(account); @@ -644,6 +655,13 @@ public class XmppConnection implements Runnable { final AckPacket ack = new AckPacket(this.stanzasReceived, smVersion); tagWriter.writeStanzaAsync(ack); } else if (nextTag.isStart("a")) { + if (mWaitingForSmCatchup.compareAndSet(true, false)) { + int count = mSmCatchupMessageCounter.get(); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": SM catchup complete (" + count + ")"); + if (count > 0) { + mXmppConnectionService.getNotificationService().finishBacklog(true, account); + } + } final Element ack = tagReader.readElement(nextTag); lastPacketReceived = SystemClock.elapsedRealtime(); try { @@ -869,7 +887,10 @@ public class XmppConnection implements Runnable { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": resuming after stanza #" + stanzasReceived); } final ResumePacket resume = new ResumePacket(this.streamId, stanzasReceived, smVersion); + this.mSmCatchupMessageCounter.set(0); + this.mWaitingForSmCatchup.set(true); this.tagWriter.writeStanzaAsync(resume); + this.tagWriter.writeStanzaAsync(new RequestPacket(smVersion)); } else if (needsBinding) { if (this.streamFeatures.hasChild("bind")) { sendBindRequest(); |