|
|
|
@ -478,7 +478,7 @@ extension MessageSender {
|
|
|
|
|
/// unregisters from push notifications.
|
|
|
|
|
///
|
|
|
|
|
/// The returned promise is fulfilled when the `MEMBER_LEFT` message has been sent to the group.
|
|
|
|
|
public static func leave(_ db: Database, groupPublicKey: String) throws -> Promise<Int64> {
|
|
|
|
|
public static func leave(_ db: Database, groupPublicKey: String) throws -> Promise<(Int64, Error?)> {
|
|
|
|
|
guard let thread: SessionThread = try? SessionThread.fetchOne(db, id: groupPublicKey) else {
|
|
|
|
|
SNLog("Can't leave nonexistent closed group.")
|
|
|
|
|
return Promise(error: MessageSenderError.noThread)
|
|
|
|
@ -503,7 +503,9 @@ extension MessageSender {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send the update to the group
|
|
|
|
|
let promise = try MessageSender
|
|
|
|
|
let (promise, seal) = Promise<(Int64, Error?)>.pending()
|
|
|
|
|
do {
|
|
|
|
|
try MessageSender
|
|
|
|
|
.sendNonDurably(
|
|
|
|
|
db,
|
|
|
|
|
message: ClosedGroupControlMessage(
|
|
|
|
@ -533,12 +535,15 @@ extension MessageSender {
|
|
|
|
|
.infoMessage(db, sender: userPublicKey)
|
|
|
|
|
).update(db)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seal.fulfill((interactionId, nil))
|
|
|
|
|
}
|
|
|
|
|
.map { _ in
|
|
|
|
|
return interactionId
|
|
|
|
|
.catch { error in
|
|
|
|
|
seal.fulfill((interactionId, error))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
seal.fulfill((interactionId, error))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the group (if the admin leaves the group is disbanded)
|
|
|
|
|
let wasAdminUser: Bool = try GroupMember
|
|
|
|
|