diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-09-17 11:32:34 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-09-17 11:32:34 +0200 |
commit | c422e960a48d8edfa560b01c17e043e90fe9c120 (patch) | |
tree | 8804ce666b706f9d8ce5accff5cea21451ebf1f8 /src/main | |
parent | 0aea51fc3da3b534b520511b437a7c435cab530b (diff) |
use history clear date as minimum date for mam
Diffstat (limited to '')
5 files changed, 43 insertions, 13 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index b48eaa39f..757aa405c 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -53,6 +53,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public static final String ATTRIBUTE_MUTED_TILL = "muted_till"; public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify"; public static final String ATTRIBUTE_CRYPTO_TARGETS = "crypto_targets"; + public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history"; private String name; private String contactUuid; @@ -332,11 +333,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public void setLastClearHistory(long time) { - setAttribute("last_clear_history",String.valueOf(time)); + setAttribute("ATTRIBUTE_LAST_CLEAR_HISTORY",String.valueOf(time)); } public long getLastClearHistory() { - return getLongAttribute("last_clear_history", 0); + return getLongAttribute("ATTRIBUTE_LAST_CLEAR_HISTORY", 0); } public List<Jid> getAcceptedCryptoTargets() { diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index ba426d49c..79eecd869 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -11,6 +11,8 @@ import android.util.Base64; import android.util.Log; import android.util.Pair; +import org.json.JSONException; +import org.json.JSONObject; import org.whispersystems.libaxolotl.AxolotlAddress; import org.whispersystems.libaxolotl.IdentityKey; import org.whispersystems.libaxolotl.IdentityKeyPair; @@ -31,7 +33,6 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; -import org.json.JSONException; import de.pixart.messenger.Config; import de.pixart.messenger.crypto.axolotl.AxolotlService; @@ -727,21 +728,37 @@ public class DatabaseBackend extends SQLiteOpenHelper { } } + public Pair<Long, String> getLastClearDate(Account account) { + SQLiteDatabase db = this.getReadableDatabase(); + String[] columns = {Conversation.ATTRIBUTES}; + String selection = Conversation.ACCOUNT + "=?"; + String[] args = {account.getUuid()}; + Cursor cursor = db.query(Conversation.TABLENAME, columns, selection, args, null, null, null); + long maxClearDate = 0; + while (cursor.moveToNext()) { + try { + final JSONObject jsonObject = new JSONObject(cursor.getString(0)); + maxClearDate = Math.max(maxClearDate, jsonObject.getLong(Conversation.ATTRIBUTE_LAST_CLEAR_HISTORY)); + } catch (Exception e) { + //ignored + } + } + cursor.close(); + return new Pair<>(maxClearDate, null); + } + private Cursor getCursorForSession(Account account, AxolotlAddress contact) { final SQLiteDatabase db = this.getReadableDatabase(); - String[] columns = null; String[] selectionArgs = {account.getUuid(), contact.getName(), Integer.toString(contact.getDeviceId())}; - Cursor cursor = db.query(SQLiteAxolotlStore.SESSION_TABLENAME, - columns, + return db.query(SQLiteAxolotlStore.SESSION_TABLENAME, + null, SQLiteAxolotlStore.ACCOUNT + " = ? AND " + SQLiteAxolotlStore.NAME + " = ? AND " + SQLiteAxolotlStore.DEVICE_ID + " = ? ", selectionArgs, null, null, null); - - return cursor; } public SessionRecord loadSession(Account account, AxolotlAddress contact) { diff --git a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java index fb8f4d1c4..4748dc86d 100644 --- a/src/main/java/de/pixart/messenger/services/MessageArchiveService.java +++ b/src/main/java/de/pixart/messenger/services/MessageArchiveService.java @@ -45,9 +45,18 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { } } } - Pair<Long,String> pair = mXmppConnectionService.databaseBackend.getLastMessageReceived(account); - long startCatchup = pair == null ? 0 : pair.first; - long endCatchup = account.getXmppConnection().getLastSessionEstablished(); + 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) { return; @@ -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); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 6be77bf9a..879fee405 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3427,7 +3427,9 @@ public class XmppConnectionService extends Service { @Override public void run() { databaseBackend.deleteMessagesInConversation(conversation); - } + databaseBackend.updateConversation(conversation); + + } }; mDatabaseExecutor.execute(runnable); } diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 5e14db91e..2e3af3ebb 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -516,6 +516,7 @@ public class MessageAdapter extends ArrayAdapter<Message> { private void loadMoreMessages(Conversation conversation) { conversation.setLastClearHistory(0); + activity.xmppConnectionService.databaseBackend.updateConversation(conversation); conversation.setHasMessagesLeftOnServer(true); conversation.setFirstMamReference(null); long timestamp = conversation.getLastMessageTransmitted(); |