From bba6eb0cc2229d2cef59c19018a3196568d5df5f Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:33:02 +1000 Subject: [PATCH] fix: some open group volatile convo fix for last read timer being set. Need to investigate further --- .../conversation/v2/ConversationActivityV2.kt | 2 +- .../org/thoughtcrime/securesms/database/Storage.kt | 12 ++---------- .../securesms/database/ThreadDatabase.java | 4 ++-- .../securesms/dependencies/DatabaseModule.kt | 6 +++++- .../securesms/groups/OpenGroupManager.kt | 1 + 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 99b0bd1901..10298c3fd8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -441,7 +441,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe // only update the conversation every 3 seconds maximum // channel is rendezvous and shouldn't block on try send calls as often as we want val bufferedFlow = bufferedLastSeenChannel.consumeAsFlow() - .debounce(1.seconds) + .debounce(30.seconds) bufferedFlow.collectLatest { withContext(Dispatchers.IO) { storage.markConversationAsRead(viewModel.threadId, SnodeAPI.nowWithOffset) 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 25877c2a55..2ad173319d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -93,10 +93,6 @@ import network.loki.messenger.libsession_util.util.Contact as LibSessionContact open class Storage(context: Context, helper: SQLCipherOpenHelper, private val configFactory: ConfigFactory) : Database(context, helper), StorageProtocol, ThreadDatabase.ConversationThreadUpdateListener { - init { - DatabaseComponent.get(context).threadDatabase().setUpdateListener(this) - } - // TODO: maybe add time here from formation / creation message override fun threadCreated(address: Address, threadId: Long) { if (!getRecipientApproved(address)) return // don't store unapproved / message requests @@ -131,9 +127,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val userProfile = configFactory.user ?: return userProfile.setNtsPriority(ConfigBase.PRIORITY_VISIBLE) } - val newVolatileParams = volatile.getOrConstructOneToOne(address.serialize()).copy( - lastRead = SnodeAPI.nowWithOffset - ) + val newVolatileParams = volatile.getOrConstructOneToOne(address.serialize()) volatile.set(newVolatileParams) } } @@ -964,7 +958,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val communityInfo = groups.getOrConstructCommunityInfo(infoServer, infoRoom, pubKeyHex) groups.set(communityInfo) val volatile = volatileConfig.getOrConstructCommunity(infoServer, infoRoom, pubKey) - volatileConfig.set(volatile) + volatileConfig.set(volatile.copy(lastRead = 0)) } override fun hasBackgroundGroupAddJob(groupJoinUrl: String): Boolean { @@ -1194,8 +1188,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co } override fun deleteConversation(threadID: Long) { - // TODO: delete from either contacts / convo volatile or the closed groups - // TODO: message request deletion properly (not just doing a hidden priority) val recipient = getRecipientForThread(threadID) val threadDB = DatabaseComponent.get(context).threadDatabase() threadDB.deleteConversation(threadID) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index c42d32c91a..4b66b91ffb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -527,11 +527,11 @@ public class ThreadDatabase extends Database { } public void setLastSeen(long threadId, long timestamp) { - SQLiteDatabase db = databaseHelper.getWritableDatabase(); - // edge case where we set the last seen time for a conversation before it loads messages (joining community for example) if (getMessageCount(threadId) <= 0) return; + SQLiteDatabase db = databaseHelper.getWritableDatabase(); + ContentValues contentValues = new ContentValues(1); long lastSeenTime = timestamp == -1 ? SnodeAPI.getNowWithOffset() : timestamp; contentValues.put(LAST_SEEN, lastSeenTime); diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/DatabaseModule.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/DatabaseModule.kt index 8fe656682e..5cb393127e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/DatabaseModule.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/DatabaseModule.kt @@ -135,7 +135,11 @@ object DatabaseModule { @Provides @Singleton - fun provideStorage(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper, configFactory: ConfigFactory) = Storage(context,openHelper, configFactory) + fun provideStorage(@ApplicationContext context: Context, openHelper: SQLCipherOpenHelper, configFactory: ConfigFactory, threadDatabase: ThreadDatabase): Storage { + val storage = Storage(context,openHelper, configFactory) + threadDatabase.setUpdateListener(storage) + return storage + } @Provides @Singleton diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt index 1f27a36c2f..a54ff7d056 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt @@ -119,6 +119,7 @@ object OpenGroupManager { } } configFactory.userGroups?.eraseCommunity(server, room) + configFactory.convoVolatile?.eraseCommunity(server, room) // Delete storage.removeLastDeletionServerID(room, server) storage.removeLastMessageServerID(room, server)