Fixed an issue where the group was in the wrong state after destroyed

pull/894/head
Morgan Pretty 6 months ago
parent ad2c9ff5a6
commit f8377e6029

@ -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],

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

Loading…
Cancel
Save