|
|
|
@ -58,24 +58,45 @@ public enum GroupLeavingJob: JobExecutor {
|
|
|
|
|
.receive(on: queue)
|
|
|
|
|
.sinkUntilComplete(
|
|
|
|
|
receiveCompletion: { result in
|
|
|
|
|
switch result {
|
|
|
|
|
case .failure:
|
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
|
try Interaction
|
|
|
|
|
.filter(id: job.interactionId)
|
|
|
|
|
.updateAll(
|
|
|
|
|
db,
|
|
|
|
|
[
|
|
|
|
|
let failureChanges: [ConfigColumnAssignment] = [
|
|
|
|
|
Interaction.Columns.variant
|
|
|
|
|
.set(to: Interaction.Variant.infoClosedGroupCurrentUserErrorLeaving),
|
|
|
|
|
Interaction.Columns.body.set(to: "group_unable_to_leave".localized())
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
success(job, false)
|
|
|
|
|
let successfulChanges: [ConfigColumnAssignment] = [
|
|
|
|
|
Interaction.Columns.variant
|
|
|
|
|
.set(to: Interaction.Variant.infoClosedGroupCurrentUserLeft),
|
|
|
|
|
Interaction.Columns.body.set(to: "GROUP_YOU_LEFT".localized())
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
case .finished:
|
|
|
|
|
// Handle the appropriate response
|
|
|
|
|
Storage.shared.writeAsync { db in
|
|
|
|
|
// If it failed due to one of these errors then clear out any associated data (as somehow
|
|
|
|
|
// the 'SessionThread' exists but not the data required to send the 'MEMBER_LEFT' message
|
|
|
|
|
// which would leave the user in a state where they can't leave the group)
|
|
|
|
|
let errorsToSucceed: [MessageSenderError] = [
|
|
|
|
|
.invalidClosedGroupUpdate,
|
|
|
|
|
.noKeyPair
|
|
|
|
|
]
|
|
|
|
|
let shouldSucceed: Bool = {
|
|
|
|
|
switch result {
|
|
|
|
|
case .failure(let error as MessageSenderError): return errorsToSucceed.contains(error)
|
|
|
|
|
case .failure: return false
|
|
|
|
|
default: return true
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
// Update the transaction
|
|
|
|
|
try Interaction
|
|
|
|
|
.filter(id: interactionId)
|
|
|
|
|
.updateAll(
|
|
|
|
|
db,
|
|
|
|
|
(shouldSucceed ? successfulChanges : failureChanges)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// If we succeed in leaving then we should try to clear the group data
|
|
|
|
|
guard shouldSucceed else { return }
|
|
|
|
|
|
|
|
|
|
// Update the group (if the admin leaves the group is disbanded)
|
|
|
|
|
let currentUserPublicKey: String = getUserHexEncodedPublicKey(db)
|
|
|
|
|
let wasAdminUser: Bool = GroupMember
|
|
|
|
@ -96,18 +117,6 @@ public enum GroupLeavingJob: JobExecutor {
|
|
|
|
|
.deleteAll(db)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the transaction
|
|
|
|
|
try Interaction
|
|
|
|
|
.filter(id: interactionId)
|
|
|
|
|
.updateAll(
|
|
|
|
|
db,
|
|
|
|
|
[
|
|
|
|
|
Interaction.Columns.variant
|
|
|
|
|
.set(to: Interaction.Variant.infoClosedGroupCurrentUserLeft),
|
|
|
|
|
Interaction.Columns.body.set(to: "GROUP_YOU_LEFT".localized())
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Clear out the group info as needed
|
|
|
|
|
try ClosedGroup.removeKeysAndUnsubscribe(
|
|
|
|
|
db,
|
|
|
|
@ -119,7 +128,6 @@ public enum GroupLeavingJob: JobExecutor {
|
|
|
|
|
|
|
|
|
|
success(job, false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|