aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/MessageArchiveService.java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/MessageArchiveService.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java
index 06df1b38..a27e6c3e 100644
--- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java
+++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java
@@ -45,8 +45,17 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
}
}
}
- Pair<Long,String> pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account);
- long startCatchup = pair == null ? 0 : pair.first;
+ final Pair<Long,String> lastMessageReceived = mXmppConnectionService.databaseBackend.getLastMessageReceived(account);
+ final Pair<Long,String> lastClearDate = mXmppConnectionService.databaseBackend.getLastClearDate(account);
+ long startCatchup;
+ final String reference;
+ if (lastMessageReceived != null && lastMessageReceived.first >= lastClearDate.first) {
+ startCatchup = lastMessageReceived.first;
+ reference = lastMessageReceived.second;
+ } else {
+ startCatchup = lastClearDate.first;
+ reference = null;
+ }
long endCatchup = account.getXmppConnection().getLastSessionEstablished();
final Query query;
if (startCatchup == 0) {
@@ -62,7 +71,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
query = new Query(account, startCatchup, endCatchup);
} else {
query = new Query(account, startCatchup, endCatchup);
- query.reference = pair.second;
+ query.reference = reference;
}
this.queries.add(query);
this.execute(query);