use last received message id when querying archive

This commit is contained in:
Daniel Gultsch 2016-04-09 10:29:34 +02:00
parent 14b46c3ee7
commit 2713fd50c8
1 changed files with 17 additions and 7 deletions

View File

@ -45,8 +45,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
} }
} }
long startCatchup = getLastMessageTransmitted(account); Pair<Long,String> pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account);
long startCatchup = pair == null ? 0 : pair.first;
long endCatchup = account.getXmppConnection().getLastSessionEstablished(); long endCatchup = account.getXmppConnection().getLastSessionEstablished();
final Query query;
if (startCatchup == 0) { if (startCatchup == 0) {
return; return;
} else if (endCatchup - startCatchup >= Config.MAM_MAX_CATCHUP) { } else if (endCatchup - startCatchup >= Config.MAM_MAX_CATCHUP) {
@ -57,8 +59,14 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
this.query(conversation,startCatchup); 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.queries.add(query);
this.execute(query); this.execute(query);
} }
@ -75,11 +83,6 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
} }
} }
private long getLastMessageTransmitted(final Account account) {
Pair<Long,String> pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account);
return pair == null ? 0 : pair.first;
}
public Query query(final Conversation conversation) { public Query query(final Conversation conversation) {
if (conversation.getLastMessageTransmitted() < 0 && conversation.countMessages() == 0) { if (conversation.getLastMessageTransmitted() < 0 && conversation.countMessages() == 0) {
return query(conversation, return query(conversation,
@ -283,6 +286,13 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
this.queryId = new BigInteger(50, mXmppConnectionService.getRNG()).toString(32); 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) { private Query page(String reference) {
Query query = new Query(this.account,this.start,this.end); Query query = new Query(this.account,this.start,this.end);
query.reference = reference; query.reference = reference;