From 38011ba76a0fb3fd57e381bc4195adcc7d7aa344 Mon Sep 17 00:00:00 2001 From: jbsession Date: Wed, 14 Jan 2026 11:49:37 +0800 Subject: [PATCH 1/3] Changes to some Stateflow and handling conversationReloadNotification --- .../conversation/v2/ConversationActivityV2.kt | 14 +++++++++----- .../conversation/v2/ConversationViewModel.kt | 8 +++++--- 2 files changed, 14 insertions(+), 8 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 289d52a65c..6a01186390 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 @@ -657,11 +657,15 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate, } lifecycleScope.launch { - viewModel.conversationReloadNotification - .collect { - LoaderManager.getInstance(this@ConversationActivityV2) - .restartLoader(0, null, this@ConversationActivityV2) - } + repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.conversationReloadNotification + .collect { + if (!firstLoad.get()) { + LoaderManager.getInstance(this@ConversationActivityV2) + .restartLoader(0, null, this@ConversationActivityV2) + } + } + } } setupMentionView() diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index 52f31f66ba..fc67caf83e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -182,7 +182,7 @@ class ConversationViewModel @AssistedInject constructor( ?: threadDb .updateNotifications .map { - withContext(Dispatchers.Default) { + withContext(Dispatchers.IO) { threadDb.getThreadIdIfExistsFor(address) } } @@ -213,11 +213,13 @@ class ConversationViewModel @AssistedInject constructor( val conversationReloadNotification: SharedFlow<*> = merge( threadIdFlow .filterNotNull() - .flatMapLatest { id -> threadDb.updateNotifications.filter { it == id } }, + .flatMapLatest { id -> threadDb.updateNotifications.filter { it == id } }, recipientSettingsDatabase.changeNotification.filter { it == address }, attachmentDatabase.changesNotification, reactionDb.changeNotification, - ).debounce(200L) // debounce to avoid too many reloads + ).combine(threadIdFlow) { event, tid -> if (tid != null) event else null } + .filterNotNull() + .debounce(350L) // debounce to avoid too many reloads .shareIn(viewModelScope, SharingStarted.Eagerly) From 92e9e7e37c42eea733fe082d42995a80ce7c5fe2 Mon Sep 17 00:00:00 2001 From: jbsession Date: Wed, 14 Jan 2026 12:11:38 +0800 Subject: [PATCH 2/3] Cleanup --- .../securesms/conversation/v2/ConversationViewModel.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index fc67caf83e..6dc2bd1bf8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -217,9 +217,7 @@ class ConversationViewModel @AssistedInject constructor( recipientSettingsDatabase.changeNotification.filter { it == address }, attachmentDatabase.changesNotification, reactionDb.changeNotification, - ).combine(threadIdFlow) { event, tid -> if (tid != null) event else null } - .filterNotNull() - .debounce(350L) // debounce to avoid too many reloads + ).debounce(200L) // debounce to avoid too many reloads .shareIn(viewModelScope, SharingStarted.Eagerly) From 65e0991dbae72dffe10d22c101ffe14d282ed79c Mon Sep 17 00:00:00 2001 From: jbsession Date: Wed, 14 Jan 2026 13:30:12 +0800 Subject: [PATCH 3/3] Changed dispatcher back to default --- .../securesms/conversation/v2/ConversationViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index 6dc2bd1bf8..1537e0c1eb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -182,7 +182,7 @@ class ConversationViewModel @AssistedInject constructor( ?: threadDb .updateNotifications .map { - withContext(Dispatchers.IO) { + withContext(Dispatchers.Default) { threadDb.getThreadIdIfExistsFor(address) } }