From 952bafaf1dfd310960166a2e5bdabab2f54a2e9d Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Mon, 21 Oct 2024 09:45:16 +1100 Subject: [PATCH] Fix/conversation deletion issues (#1695) * SES-2464 - properly heading to home root when deleting a thread * SES-2810 - Catering for missing config contacts vs local contacts Making sure we deleted conversations when a contact is missing from the config while existing locally --- .../conversation/v2/ConversationActivityV2.kt | 11 ++++++----- .../org/thoughtcrime/securesms/database/Storage.kt | 10 ++++++++++ 2 files changed, 16 insertions(+), 5 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 0132a876cf..9cdb76cf25 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 @@ -57,7 +57,6 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch @@ -109,14 +108,14 @@ import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel import org.thoughtcrime.securesms.contacts.SelectContactsActivity.Companion.selectedContactsKey import org.thoughtcrime.securesms.conversation.ConversationActionBarDelegate import org.thoughtcrime.securesms.conversation.disappearingmessages.DisappearingMessagesActivity -import org.thoughtcrime.securesms.conversation.v2.ConversationViewModel.Commands.* import org.thoughtcrime.securesms.conversation.v2.ConversationReactionOverlay.OnActionSelectedListener import org.thoughtcrime.securesms.conversation.v2.ConversationReactionOverlay.OnReactionSelectedListener +import org.thoughtcrime.securesms.conversation.v2.ConversationViewModel.Commands.* import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.MESSAGE_TIMESTAMP +import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.ON_COPY import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.ON_DELETE import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.ON_REPLY import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.ON_RESEND -import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.ON_COPY import org.thoughtcrime.securesms.conversation.v2.MessageDetailActivity.Companion.ON_SAVE import org.thoughtcrime.securesms.conversation.v2.dialogs.BlockedDialog import org.thoughtcrime.securesms.conversation.v2.dialogs.LinkPreviewDialog @@ -157,6 +156,8 @@ import org.thoughtcrime.securesms.database.model.MmsMessageRecord import org.thoughtcrime.securesms.database.model.ReactionRecord import org.thoughtcrime.securesms.giph.ui.GiphyActivity import org.thoughtcrime.securesms.groups.OpenGroupManager +import org.thoughtcrime.securesms.home.HomeActivity +import org.thoughtcrime.securesms.home.startHomeActivity import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel @@ -850,8 +851,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe binding.messageRequestBar.visibility = View.GONE } if (!uiState.conversationExists && !isFinishing) { - // Conversation should be deleted now, just go back - finish() + // Conversation should be deleted now, go to homepage with a cleared stack + baseContext.startHomeActivity(isFromOnboarding = false, isNewAccount = false) } // show or hide the text input 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 d8460159fe..4fd9f97ede 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -1265,6 +1265,16 @@ open class Storage( } setRecipientHash(recipient, contact.hashCode().toString()) } + + // if we have contacts locally but that are missing from the config, remove their corresponding thread + val removedContacts = getAllContacts().filter { localContact -> + moreContacts.firstOrNull { + it.id == localContact.accountID + } == null + } + removedContacts.forEach { + getThreadId(fromSerialized(it.accountID))?.let(::deleteConversation) + } } override fun addContacts(contacts: List) {