mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 11:05:25 +00:00
Delete group thread upon config changes
This commit is contained in:
parent
4998cebfd3
commit
7f008b5f1b
@ -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 }
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user