|
|
|
@ -50,8 +50,21 @@ public enum GroupLeavingJob: JobExecutor {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
.done(on: queue) { _ in
|
|
|
|
|
// Remove the group from the database and unsubscribe from PNs
|
|
|
|
|
ClosedGroupPoller.shared.stopPolling(for: details.groupPublicKey)
|
|
|
|
|
|
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
|
try MessageSender.performClosedGroupCleanUp(db, for: closedGroup, in: thread)
|
|
|
|
|
let userPublicKey: String = getUserHexEncodedPublicKey(db)
|
|
|
|
|
|
|
|
|
|
try closedGroup
|
|
|
|
|
.keyPairs
|
|
|
|
|
.deleteAll(db)
|
|
|
|
|
|
|
|
|
|
let _ = PushNotificationAPI.performOperation(
|
|
|
|
|
.unsubscribe,
|
|
|
|
|
for: details.groupPublicKey,
|
|
|
|
|
publicKey: userPublicKey
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try Interaction
|
|
|
|
|
.filter(id: interactionId)
|
|
|
|
@ -63,6 +76,25 @@ public enum GroupLeavingJob: JobExecutor {
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Update the group (if the admin leaves the group is disbanded)
|
|
|
|
|
let wasAdminUser: Bool = try GroupMember
|
|
|
|
|
.filter(GroupMember.Columns.groupId == thread.id)
|
|
|
|
|
.filter(GroupMember.Columns.profileId == userPublicKey)
|
|
|
|
|
.filter(GroupMember.Columns.role == GroupMember.Role.admin)
|
|
|
|
|
.isNotEmpty(db)
|
|
|
|
|
|
|
|
|
|
if wasAdminUser {
|
|
|
|
|
try GroupMember
|
|
|
|
|
.filter(GroupMember.Columns.groupId == thread.id)
|
|
|
|
|
.deleteAll(db)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
try GroupMember
|
|
|
|
|
.filter(GroupMember.Columns.groupId == thread.id)
|
|
|
|
|
.filter(GroupMember.Columns.profileId == userPublicKey)
|
|
|
|
|
.deleteAll(db)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if details.deleteThread {
|
|
|
|
|
_ = try SessionThread
|
|
|
|
|
.filter(id: thread.id)
|
|
|
|
|