From 2713fd50c830e0c139ea4ae3194bdd60126bb968 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 9 Apr 2016 10:29:34 +0200 Subject: use last received message id when querying archive --- .../services/MessageArchiveService.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index e8616bd8..a50b45b1 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -45,8 +45,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } } - long startCatchup = getLastMessageTransmitted(account); + Pair pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account); + long startCatchup = pair == null ? 0 : pair.first; long endCatchup = account.getXmppConnection().getLastSessionEstablished(); + final Query query; if (startCatchup == 0) { return; } else if (endCatchup - startCatchup >= Config.MAM_MAX_CATCHUP) { @@ -57,8 +59,14 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { this.query(conversation,startCatchup); } } + query = new Query(account, startCatchup, endCatchup); + } else { + if (pair.second == null) { + query = new Query(account, startCatchup, endCatchup); + } else { + query = new Query(account, pair.second, endCatchup); + } } - final Query query = new Query(account, startCatchup, endCatchup); this.queries.add(query); this.execute(query); } @@ -75,11 +83,6 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } - private long getLastMessageTransmitted(final Account account) { - Pair pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account); - return pair == null ? 0 : pair.first; - } - public Query query(final Conversation conversation) { if (conversation.getLastMessageTransmitted() < 0 && conversation.countMessages() == 0) { return query(conversation, @@ -283,6 +286,13 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { this.queryId = new BigInteger(50, mXmppConnectionService.getRNG()).toString(32); } + public Query(Account account, String reference, long end) { + this.account = account; + this.reference = reference; + this.end = end; + this.queryId = new BigInteger(50, mXmppConnectionService.getRNG()).toString(32); + } + private Query page(String reference) { Query query = new Query(this.account,this.start,this.end); query.reference = reference; -- cgit v1.2.3