Show a loader while a group is updating

pull/387/head
Niels Andriesse 4 years ago
parent f2f5dcdfc2
commit 5f37eddfa1

@ -1,3 +1,4 @@
import PromiseKit
@objc(SNEditClosedGroupVC) @objc(SNEditClosedGroupVC)
final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegate { final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegate {
@ -268,22 +269,26 @@ final class EditClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelega
guard members.count <= 100 else { guard members.count <= 100 else {
return showError(title: NSLocalizedString("vc_create_closed_group_too_many_group_members_error", comment: "")) return showError(title: NSLocalizedString("vc_create_closed_group_too_many_group_members_error", comment: ""))
} }
Storage.write(with: { [weak self] transaction in var promise: Promise<Void>!
do { ModalActivityIndicatorViewController.present(fromViewController: navigationController!) { [weak self] _ in
Storage.write(with: { transaction in
if !members.contains(getUserHexEncodedPublicKey()) { if !members.contains(getUserHexEncodedPublicKey()) {
try MessageSender.leave(groupPublicKey, using: transaction) promise = MessageSender.leave(groupPublicKey, using: transaction)
} else { } else {
try MessageSender.update(groupPublicKey, with: members, name: name, transaction: transaction) promise = MessageSender.update(groupPublicKey, with: members, name: name, transaction: transaction)
} }
} catch { }, completion: {
DispatchQueue.main.async { let _ = promise.done(on: DispatchQueue.main) {
self?.showError(title: "Couldn't Update Group", message: "Please check your internet connection and try again.") guard let self = self else { return }
self.dismiss(animated: true, completion: nil) // Dismiss the loader
popToConversationVC(self)
} }
} promise.catch(on: DispatchQueue.main) { error in
}, completion: { [weak self] in self?.dismiss(animated: true, completion: nil) // Dismiss the loader
guard let self = self else { return } self?.showError(title: "Couldn't Update Group", message: error.localizedDescription)
popToConversationVC(self) }
}) })
}
} }
// MARK: Convenience // MARK: Convenience

@ -372,7 +372,7 @@ extension MessageReceiver {
case .membersAdded: handleClosedGroupMembersAdded(message, using: transaction) case .membersAdded: handleClosedGroupMembersAdded(message, using: transaction)
case .membersRemoved: handleClosedGroupMembersRemoved(message, using: transaction) case .membersRemoved: handleClosedGroupMembersRemoved(message, using: transaction)
case .memberLeft: handleClosedGroupMemberLeft(message, using: transaction) case .memberLeft: handleClosedGroupMemberLeft(message, using: transaction)
case .encryptionKeyPairRequest: handleClosedGroupEncryptionKeyPairRequest(message, using: transaction) case .encryptionKeyPairRequest: handleClosedGroupEncryptionKeyPairRequest(message, using: transaction) // Currently not used
} }
} }

Loading…
Cancel
Save