From c5299c101007955dd2eca1e47846a8ff0778b059 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Wed, 24 May 2023 14:12:49 +1000 Subject: [PATCH] fix: update last seen if later than current --- .../java/org/thoughtcrime/securesms/database/MmsDatabase.kt | 5 ++++- .../org/thoughtcrime/securesms/database/SmsDatabase.java | 5 ++++- .../main/java/org/thoughtcrime/securesms/database/Storage.kt | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt index 29f3a1bea0..3aab50acf4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt @@ -739,7 +739,10 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa ) } with (get(context).threadDatabase()) { - setLastSeen(threadId, message.sentTimeMillis) + val lastSeen = getLastSeenAndHasSent(threadId).first() + if (lastSeen < message.sentTimeMillis) { + setLastSeen(threadId, message.sentTimeMillis) + } setHasSent(threadId, true) if (runThreadUpdate) { update(threadId, true, true) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java index 3cdade90e2..4ef576f404 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -564,7 +564,10 @@ public class SmsDatabase extends MessagingDatabase { if (runThreadUpdate) { DatabaseComponent.get(context).threadDatabase().update(threadId, true, true); } - DatabaseComponent.get(context).threadDatabase().setLastSeen(threadId, message.getSentTimestampMillis()); + long lastSeen = DatabaseComponent.get(context).threadDatabase().getLastSeenAndHasSent(threadId).first(); + if (lastSeen < message.getSentTimestampMillis()) { + DatabaseComponent.get(context).threadDatabase().setLastSeen(threadId, message.getSentTimestampMillis()); + } DatabaseComponent.get(context).threadDatabase().setHasSent(threadId, true); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 5867afc108..eb8ad10105 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -482,7 +482,9 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co is Conversation.Community -> getThreadIdFor("",null, "${conversation.baseCommunityInfo.baseUrl}.${conversation.baseCommunityInfo.room}", createThread = false) } if (threadId != null) { - markConversationAsRead(threadId, conversation.lastRead) + if (conversation.lastRead > getLastSeen(threadId)) { + markConversationAsRead(threadId, conversation.lastRead) + } updateThread(threadId, false) } }