diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-12-14 23:23:32 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-12-14 23:23:56 +0100 |
commit | f8a496a5f1e225585d0ecaec68fb81e8cffa3083 (patch) | |
tree | 5302fbcc8b14bf8f07c7c9c27332bbd703ba2efe | |
parent | 5cbae258084a5f77857c5f535451fe3b459ce0d1 (diff) |
run mam queries only when online
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/MessageArchiveService.java | 34 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 1 |
2 files changed, 31 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 9dfe179c..fe1871ea 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -3,7 +3,9 @@ package eu.siacs.conversations.services; import android.util.Log; import java.math.BigInteger; +import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import eu.siacs.conversations.Config; @@ -22,6 +24,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { private final XmppConnectionService mXmppConnectionService; private final HashSet<Query> queries = new HashSet<Query>(); + private ArrayList<Query> pendingQueries = new ArrayList<Query>(); public enum PagingOrder { NORMAL, @@ -83,18 +86,41 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } + public void executePendingQueries(final Account account) { + List<Query> pending = new ArrayList<>(); + synchronized(this.pendingQueries) { + for(Iterator<Query> iterator = this.pendingQueries.iterator(); iterator.hasNext();) { + Query query = iterator.next(); + if (query.getAccount() == account) { + pending.add(query); + iterator.remove(); + } + } + } + for(Query query : pending) { + this.execute(query); + } + } + private void execute(final Query query) { - Log.d(Config.LOGTAG,query.getAccount().getJid().toBareJid().toString()+": running mam query "+query.toString()); - IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query); - this.mXmppConnectionService.sendIqPacket(query.getAccount(), packet, new OnIqPacketReceived() { + final Account account= query.getAccount(); + if (account.getStatus() == Account.State.ONLINE) { + Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": running mam query " + query.toString()); + IqPacket packet = this.mXmppConnectionService.getIqGenerator().queryMessageArchiveManagement(query); + this.mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { if (packet.getType() == IqPacket.TYPE_ERROR) { - Log.d(Config.LOGTAG,account.getJid().toBareJid().toString()+": error executing mam: "+packet.toString()); + Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": error executing mam: " + packet.toString()); finalizeQuery(query); } } }); + } else { + synchronized (this.pendingQueries) { + this.pendingQueries.add(query); + } + } } private void finalizeQuery(Query query) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 9b1ecdea..b7ca699c 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -160,6 +160,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa for (Conversation conversation : account.pendingConferenceJoins) { joinMuc(conversation); } + mMessageArchiveService.executePendingQueries(account); mJingleConnectionManager.cancelInTransmission(); List<Conversation> conversations = getConversations(); for (Conversation conversation : conversations) { |