From 11d4add8f95e2eb5950303e02b3389f8d633cd9c Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 27 Jul 2020 09:17:49 +1000 Subject: [PATCH] Show a loader while an open group is being joined --- .../View Controllers/JoinPublicChatVC.swift | 37 ++++++++++--------- .../View Controllers/NewClosedGroupVC.swift | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift b/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift index d76c4c423..78d6b8f7d 100644 --- a/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift +++ b/Signal/src/Loki/View Controllers/JoinPublicChatVC.swift @@ -142,24 +142,27 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: PublicChatAPI.lastMessageServerIDCollection) transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: PublicChatAPI.lastDeletionServerIDCollection) } - PublicChatManager.shared.addChat(server: urlAsString, channel: channelID) - .done(on: .main) { [weak self] _ in - let _ = PublicChatAPI.setDisplayName(to: displayName, on: urlAsString) - let _ = PublicChatAPI.setProfilePictureURL(to: profilePictureURL, using: profileKey, on: urlAsString) - let _ = PublicChatAPI.join(channelID, on: urlAsString) - let syncManager = SSKEnvironment.shared.syncManager - let _ = syncManager.syncAllOpenGroups() - self?.presentingViewController!.dismiss(animated: true, completion: nil) - } - .catch(on: .main) { [weak self] error in - var title = NSLocalizedString("Couldn't Join", comment: "") - var message = "" - if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 { - title = NSLocalizedString("Unauthorized", comment: "") - message = NSLocalizedString("Please ask the open group operator to add you to the group.", comment: "") + ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in + PublicChatManager.shared.addChat(server: urlAsString, channel: channelID) + .done(on: DispatchQueue.main) { [weak self] _ in + let _ = PublicChatAPI.setDisplayName(to: displayName, on: urlAsString) + let _ = PublicChatAPI.setProfilePictureURL(to: profilePictureURL, using: profileKey, on: urlAsString) + let _ = PublicChatAPI.join(channelID, on: urlAsString) + let syncManager = SSKEnvironment.shared.syncManager + let _ = syncManager.syncAllOpenGroups() + self?.presentingViewController!.dismiss(animated: true, completion: nil) + } + .catch(on: DispatchQueue.main) { [weak self] error in + self?.dismiss(animated: true, completion: nil) // Dismiss the loader + var title = NSLocalizedString("Couldn't Join", comment: "") + var message = "" + if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 { + title = NSLocalizedString("Unauthorized", comment: "") + message = NSLocalizedString("Please ask the open group operator to add you to the group.", comment: "") + } + self?.isJoining = false + self?.showError(title: title, message: message) } - self?.isJoining = false - self?.showError(title: title, message: message) } } diff --git a/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift b/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift index 836bc64c8..502e7b0e7 100644 --- a/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift +++ b/Signal/src/Loki/View Controllers/NewClosedGroupVC.swift @@ -189,7 +189,7 @@ final class NewClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegat self?.presentingViewController?.dismiss(animated: true, completion: nil) SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false) }.catch(on: DispatchQueue.main) { _ in - self?.dismiss(animated: true, completion: nil) // Dismiss the modal + self?.dismiss(animated: true, completion: nil) // Dismiss the loader let title = NSLocalizedString("Couldn't Create Group", comment: "") let message = NSLocalizedString("Please check your internet connection and try again.", comment: "") let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)