From 7f008b5f1b9098b42f40d9581cb6059e088bd65b Mon Sep 17 00:00:00 2001 From: SessionHero01 <180888785+SessionHero01@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:00:31 +1100 Subject: [PATCH] Delete group thread upon config changes --- .../securesms/configs/ConfigToDatabaseSync.kt | 16 ++++++++++++++-- .../session/libsession/utilities/GroupRecord.kt | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt b/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt index 0232c5ed8d..004ec48699 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt @@ -203,7 +203,7 @@ class ConfigToDatabaseSync @Inject constructor( val existingLegacyClosedGroups = storage.getAllGroups(includeInactive = true).filter { it.isLegacyClosedGroup } val lgcIds = lgc.map { it.accountId } - val toDeleteClosedGroups = existingLegacyClosedGroups.filter { group -> + val toDeleteLegacyClosedGroups = existingLegacyClosedGroups.filter { group -> GroupUtil.doubleDecodeGroupId(group.encodedId) !in lgcIds } @@ -212,7 +212,7 @@ class ConfigToDatabaseSync @Inject constructor( OpenGroupManager.delete(openGroup.server, openGroup.room, context) } - toDeleteClosedGroups.forEach { deleteGroup -> + toDeleteLegacyClosedGroups.forEach { deleteGroup -> val threadId = storage.getThreadId(deleteGroup.encodedId) if (threadId != null) { ClosedGroupManager.silentlyRemoveGroup(context,threadId, @@ -237,6 +237,7 @@ class ConfigToDatabaseSync @Inject constructor( } val newClosedGroups = userGroups.allClosedGroupInfo() + val existingClosedGroups = storage.getAllGroups(includeInactive = true).filter { it.isClosedGroupV2 } for (closedGroup in newClosedGroups) { val recipient = Recipient.from(context, fromSerialized(closedGroup.groupAccountId.hexString), false) storage.setRecipientApprovedMe(recipient, true) @@ -248,6 +249,17 @@ class ConfigToDatabaseSync @Inject constructor( } } + val toRemove = existingClosedGroups.mapTo(hashSetOf()) { it.encodedId } - newClosedGroups.mapTo(hashSetOf()) { it.groupAccountId.hexString } + Log.d(TAG, "Removing ${toRemove.size} closed groups") + toRemove.forEach { encodedId -> + val threadId = storage.getThreadId(encodedId) + if (threadId != null) { + storage.removeClosedGroupThread(threadId) + } + + pollerFactory.pollerFor(AccountId(encodedId))?.stop() + } + for (group in lgc) { val groupId = GroupUtil.doubleEncodeGroupID(group.accountId) val existingGroup = existingLegacyClosedGroups.firstOrNull { GroupUtil.doubleDecodeGroupId(it.encodedId) == group.accountId } diff --git a/libsession/src/main/java/org/session/libsession/utilities/GroupRecord.kt b/libsession/src/main/java/org/session/libsession/utilities/GroupRecord.kt index 177065830f..a957fa088e 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/GroupRecord.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/GroupRecord.kt @@ -25,6 +25,8 @@ class GroupRecord( get() = Address.fromSerialized(encodedId).isCommunity val isLegacyClosedGroup: Boolean get() = Address.fromSerialized(encodedId).isLegacyClosedGroup + val isClosedGroupV2: Boolean + get() = Address.fromSerialized(encodedId).isClosedGroupV2 init { if (!TextUtils.isEmpty(members)) {