diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-12-11 13:52:04 +0100 |
---|---|---|
committer | Christian S <christian@pix-art.de> | 2015-12-12 15:53:34 +0100 |
commit | 459984c47c064a6392132a4b50d129a5b9d0c4ff (patch) | |
tree | dfb9c787b9efb94f46b99917e329335994172fb0 /src/main/java/eu/siacs/conversations/services | |
parent | c3df02f981c16defbf37b4ac4c64cae43c409874 (diff) |
get rid of lastMessageTransmitted in favor of db query
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/MessageArchiveService.java | 29 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 4 |
2 files changed, 8 insertions, 25 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 8847cfcd5..13261951b 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.services; import android.util.Log; +import android.util.Pair; import java.math.BigInteger; import java.util.ArrayList; @@ -75,16 +76,8 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } private long getLastMessageTransmitted(final Account account) { - long timestamp = 0; - for(final Conversation conversation : mXmppConnectionService.getConversations()) { - if (conversation.getAccount() == account) { - long tmp = conversation.getLastMessageTransmitted(); - if (tmp > timestamp) { - timestamp = tmp; - } - } - } - return timestamp; + Pair<Long,String> pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account); + return pair == null ? 0 : pair.first; } public Query query(final Conversation conversation) { @@ -166,25 +159,19 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { final Conversation conversation = query.getConversation(); if (conversation != null) { conversation.sort(); - if (conversation.setLastMessageTransmitted(query.getEnd())) { - this.mXmppConnectionService.databaseBackend.updateConversation(conversation); - } conversation.setHasMessagesLeftOnServer(query.getMessageCount() > 0); - if (query.hasCallback()) { - query.callback(); - } else { - this.mXmppConnectionService.updateConversationUi(); - } } else { for(Conversation tmp : this.mXmppConnectionService.getConversations()) { if (tmp.getAccount() == query.getAccount()) { tmp.sort(); - if (tmp.setLastMessageTransmitted(query.getEnd())) { - this.mXmppConnectionService.databaseBackend.updateConversation(tmp); - } } } } + if (query.hasCallback()) { + query.callback(); + } else { + this.mXmppConnectionService.updateConversationUi(); + } } public boolean queryInProgress(Conversation conversation, XmppConnectionService.OnMoreMessagesLoaded callback) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 1a0153e51..cb193167a 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -221,9 +221,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa Message message = conversation.findUnsentMessageWithUuid(uuid); if (message != null) { markMessage(message, Message.STATUS_SEND); - if (conversation.setLastMessageTransmitted(System.currentTimeMillis())) { - databaseBackend.updateConversation(conversation); - } } } } @@ -2883,7 +2880,6 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public void clearConversationHistory(final Conversation conversation) { conversation.clearMessages(); conversation.setHasMessagesLeftOnServer(false); //avoid messages getting loaded through mam - conversation.resetLastMessageTransmitted(); Runnable runnable = new Runnable() { @Override public void run() { |