From dec179f4e72b0741d3ae33f12fe049740454f036 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Thu, 25 May 2023 17:51:30 +1000 Subject: [PATCH] fix: open group comparison issues potentially, have to update some more outgoing message open group flags for visibility of details etc --- .../org/thoughtcrime/securesms/database/Storage.kt | 7 +++---- .../thoughtcrime/securesms/groups/OpenGroupManager.kt | 10 ++++------ .../org/thoughtcrime/securesms/home/HomeActivity.kt | 4 +++- .../securesms/home/UserDetailsBottomSheet.kt | 8 ++++++-- .../java/org/session/libsession/utilities/Address.kt | 3 +++ .../libsession/utilities/recipients/Recipient.java | 4 ++++ 6 files changed, 23 insertions(+), 13 deletions(-) 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 0ed7665a96..cef4b4897b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -501,7 +501,9 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val communities = userGroups.allCommunityInfo() val lgc = userGroups.allLegacyGroupInfo() val allOpenGroups = getAllOpenGroups() - val toDeleteCommunities = allOpenGroups.filter { it.value.joinURL !in communities.map { it.community.fullUrl() } } + val toDeleteCommunities = allOpenGroups.filter { + Conversation.Community(BaseCommunityInfo(it.value.server, it.value.room, it.value.publicKey), 0, false).baseCommunityInfo.fullUrl() !in communities.map { it.community.fullUrl() } + } val existingCommunities: Map = allOpenGroups.filterKeys { it !in toDeleteCommunities.keys } val toAddCommunities = communities.filter { it.community.fullUrl() !in existingCommunities.map { it.value.joinURL } } @@ -521,7 +523,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co toDeleteClosedGroups.forEach { deleteGroup -> val threadId = getThreadId(deleteGroup.encodedId) if (threadId != null) { - Log.d("Loki-DBG", "Deleting group for thread $threadId") ClosedGroupManager.silentlyRemoveGroup(context,threadId,GroupUtil.doubleDecodeGroupId(deleteGroup.encodedId), deleteGroup.encodedId, localUserPublicKey, delete = true) } } @@ -529,7 +530,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co toAddCommunities.forEach { toAddCommunity -> val joinUrl = toAddCommunity.community.fullUrl() if (!hasBackgroundGroupAddJob(joinUrl)) { - Log.d("Loki-DBG", "Doesn't contain background job for open group, adding from config update") JobQueue.shared.add(BackgroundGroupAddJob(joinUrl)) } } @@ -550,7 +550,6 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val existingGroup = existingClosedGroups.firstOrNull { GroupUtil.doubleDecodeGroupId(it.encodedId) == group.sessionId } val existingThread = existingGroup?.let { getThreadId(existingGroup.encodedId) } if (existingGroup != null) { - Log.d("Loki-DBG", "Existing closed group, don't add") if (group.priority == PRIORITY_HIDDEN && existingThread != null) { threadDb.deleteConversation(existingThread) // TODO: stop polling here also 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 227621d7fd..39fe26405c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/OpenGroupManager.kt @@ -9,7 +9,6 @@ import org.session.libsession.messaging.open_groups.OpenGroup import org.session.libsession.messaging.open_groups.OpenGroupApi import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPoller import org.session.libsignal.utilities.Log -import org.session.libsignal.utilities.ThreadUtils import org.thoughtcrime.securesms.dependencies.DatabaseComponent import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities import java.util.concurrent.Executors @@ -106,6 +105,7 @@ object OpenGroupManager { } } + @WorkerThread fun delete(server: String, room: String, context: Context) { val storage = MessagingModuleConfiguration.shared.storage val configFactory = MessagingModuleConfiguration.shared.configFactory @@ -133,11 +133,9 @@ object OpenGroupManager { storage.removeLastOutboxMessageId(server) val lokiThreadDB = DatabaseComponent.get(context).lokiThreadDatabase() lokiThreadDB.removeOpenGroupChat(threadID) - ThreadUtils.queue { - storage.deleteConversation(threadID) // Must be invoked on a background thread - GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread - ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context) - } + storage.deleteConversation(threadID) // Must be invoked on a background thread + GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread + ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context) } @WorkerThread diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 9a3f92f038..8ec9b44278 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -650,7 +650,9 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), // Delete the conversation val v2OpenGroup = DatabaseComponent.get(this@HomeActivity).lokiThreadDatabase().getOpenGroupChat(threadID) if (v2OpenGroup != null) { - OpenGroupManager.delete(v2OpenGroup.server, v2OpenGroup.room, this@HomeActivity) + withContext(Dispatchers.IO) { + OpenGroupManager.delete(v2OpenGroup.server, v2OpenGroup.room, this@HomeActivity) + } } else { lifecycleScope.launch(Dispatchers.IO) { storage.deleteConversation(threadID) diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt index 71d3a5fff3..35c63b148b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/UserDetailsBottomSheet.kt @@ -60,7 +60,7 @@ class UserDetailsBottomSheet: BottomSheetDialogFragment() { profilePictureView.root.update(recipient) nameTextViewContainer.visibility = View.VISIBLE nameTextViewContainer.setOnClickListener { - if (recipient.isOpenGroupInboxRecipient) return@setOnClickListener + if (recipient.isOpenGroupInboxRecipient || recipient.isOpenGroupOutboxRecipient) return@setOnClickListener nameTextViewContainer.visibility = View.INVISIBLE nameEditTextContainer.visibility = View.VISIBLE nicknameEditText.text = null @@ -88,8 +88,12 @@ class UserDetailsBottomSheet: BottomSheetDialogFragment() { nameTextView.text = recipient.name ?: publicKey // Uses the Contact API internally nameEditIcon.isVisible = threadRecipient.isContactRecipient + && !threadRecipient.isOpenGroupInboxRecipient + && !threadRecipient.isOpenGroupOutboxRecipient - publicKeyTextView.isVisible = !threadRecipient.isOpenGroupRecipient && !threadRecipient.isOpenGroupInboxRecipient + publicKeyTextView.isVisible = !threadRecipient.isOpenGroupRecipient + && !threadRecipient.isOpenGroupInboxRecipient + && !threadRecipient.isOpenGroupOutboxRecipient messageButton.isVisible = !threadRecipient.isOpenGroupRecipient || IdPrefix.fromValue(publicKey) == IdPrefix.BLINDED publicKeyTextView.text = publicKey publicKeyTextView.setOnLongClickListener { diff --git a/libsession/src/main/java/org/session/libsession/utilities/Address.kt b/libsession/src/main/java/org/session/libsession/utilities/Address.kt index 12ed4d0287..3ece5390a0 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/Address.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/Address.kt @@ -5,6 +5,7 @@ import android.os.Parcel import android.os.Parcelable import android.util.Pair import androidx.annotation.VisibleForTesting +import org.session.libsignal.utilities.IdPrefix import org.session.libsignal.utilities.Util import org.session.libsignal.utilities.guava.Optional import java.util.Collections @@ -26,6 +27,8 @@ class Address private constructor(address: String) : Parcelable, Comparable