Delete group thread upon config changes

This commit is contained in:
SessionHero01 2024-10-07 16:00:31 +11:00
parent 4998cebfd3
commit 7f008b5f1b
No known key found for this signature in database
2 changed files with 16 additions and 2 deletions

View File

@ -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 }

View File

@ -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)) {