diff --git a/SessionMessagingKit/LibSession/Config Handling/LibSession+GroupInfo.swift b/SessionMessagingKit/LibSession/Config Handling/LibSession+GroupInfo.swift index 8c596c74d..2aa3bda09 100644 --- a/SessionMessagingKit/LibSession/Config Handling/LibSession+GroupInfo.swift +++ b/SessionMessagingKit/LibSession/Config Handling/LibSession+GroupInfo.swift @@ -42,10 +42,12 @@ internal extension LibSessionCacheType { guard configNeedsDump(config) else { return } guard case .object(let conf) = config else { throw LibSessionError.invalidConfigObject } - // If the group is destroyed then remove the group data (want to keep the group itself around because - // the UX of conversations randomly disappearing isn't great) - no other changes matter and this - // can't be reversed + // If the group is destroyed then mark the group as kicked in the USER_GROUPS config and remove + // the group data (want to keep the group itself around because the UX of conversations randomly + // disappearing isn't great) - no other changes matter and this can't be reversed guard !groups_info_is_destroyed(conf) else { + try markAsKicked(db, groupSessionIds: [groupSessionId.hexString], using: dependencies) + try ClosedGroup.removeData( db, threadIds: [groupSessionId.hexString], diff --git a/SessionMessagingKit/LibSession/Config Handling/LibSession+UserGroups.swift b/SessionMessagingKit/LibSession/Config Handling/LibSession+UserGroups.swift index b9b0d5ae0..2021e62c9 100644 --- a/SessionMessagingKit/LibSession/Config Handling/LibSession+UserGroups.swift +++ b/SessionMessagingKit/LibSession/Config Handling/LibSession+UserGroups.swift @@ -581,6 +581,26 @@ internal extension LibSessionCacheType { return ugroups_group_is_kicked(&userGroup) } + + func markAsKicked( + _ db: Database, + groupSessionIds: [String], + using dependencies: Dependencies + ) throws { + try performAndPushChange(db, for: .userGroups, sessionId: dependencies[cache: .general].sessionId) { config in + guard case .object(let conf) = config else { throw LibSessionError.invalidConfigObject } + + try groupSessionIds.forEach { groupId in + var cGroupId: [CChar] = try groupId.cString(using: .utf8) ?? { throw LibSessionError.invalidCConversion }() + var userGroup: ugroups_group_info = ugroups_group_info() + + guard user_groups_get_group(conf, &userGroup, &cGroupId) else { return } + + ugroups_group_set_kicked(&userGroup) + user_groups_set_group(conf, &userGroup) + } + } + } } internal extension LibSession { @@ -1128,19 +1148,7 @@ public extension LibSession { guard !groupSessionIds.isEmpty else { return } try dependencies.mutate(cache: .libSession) { cache in - try cache.performAndPushChange(db, for: .userGroups, sessionId: dependencies[cache: .general].sessionId) { config in - guard case .object(let conf) = config else { throw LibSessionError.invalidConfigObject } - - try groupSessionIds.forEach { groupId in - var cGroupId: [CChar] = try groupId.cString(using: .utf8) ?? { throw LibSessionError.invalidCConversion }() - var userGroup: ugroups_group_info = ugroups_group_info() - - guard user_groups_get_group(conf, &userGroup, &cGroupId) else { return } - - ugroups_group_set_kicked(&userGroup) - user_groups_set_group(conf, &userGroup) - } - } + try cache.markAsKicked(db, groupSessionIds: groupSessionIds, using: dependencies) } }