pull/333/head
nielsandriesse 4 years ago
parent 3ec4e0ae52
commit 947287e42f

@ -132,20 +132,22 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
}
isJoining = true
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in
OpenGroupManager.shared.addOpenGroup(with: urlAsString)
.done(on: DispatchQueue.main) { [weak self] _ in
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 = "Couldn't Join"
var message = ""
if case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
title = "Unauthorized"
message = "Please ask the open group operator to add you to the group."
Storage.shared.write { transaction in
OpenGroupManager.shared.addOpenGroup(with: urlAsString, using: transaction)
.done(on: DispatchQueue.main) { [weak self] _ in
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 = "Couldn't Join"
var message = ""
if case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
title = "Unauthorized"
message = "Please ask the open group operator to add you to the group."
}
self?.isJoining = false
self?.showError(title: title, message: message)
}
self?.isJoining = false
self?.showError(title: title, message: message)
}
}
}

@ -19,6 +19,7 @@ final class MultiDeviceVC : BaseVC {
private lazy var toggle: UISwitch = {
let result = UISwitch()
result.onTintColor = Colors.accent
result.isOn = UserDefaults.standard[.isUsingMultiDevice]
return result
}()

@ -51,7 +51,7 @@ final class NukeDataModal : Modal {
@objc private func nuke() {
func proceed() {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in
ModalActivityIndicatorViewController.present(fromViewController: self, canCancel: false) { [weak self] _ in
appDelegate.forceSyncConfigurationNowIfNeeded().done(on: DispatchQueue.main) {
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later

@ -2,5 +2,5 @@ import PromiseKit
public protocol OpenGroupManagerProtocol {
func addOpenGroup(with url: String) -> Promise<Void>
func addOpenGroup(with url: String, using transaction: Any) -> Promise<Void>
}

@ -104,7 +104,7 @@ extension MessageReceiver {
let allOpenGroups = Set(storage.getAllUserOpenGroups().keys)
for openGroupURL in message.openGroups {
guard !allOpenGroups.contains(openGroupURL) else { continue }
SNMessagingKitConfiguration.shared.openGroupManager.addOpenGroup(with: openGroupURL).retainUntilComplete()
SNMessagingKitConfiguration.shared.openGroupManager.addOpenGroup(with: openGroupURL, using: transaction).retainUntilComplete()
}
}

@ -137,8 +137,8 @@ public final class MessageSender : NSObject {
}
// Validate the message
guard message.isValid else { handleFailure(with: Error.invalidMessage, using: transaction); return promise }
// Stop here if this is a self-send
guard !isSelfSend else {
// Stop here if this is a self-send (unless it's a configuration message)
guard !isSelfSend || message is ConfigurationMessage else {
storage.write(with: { transaction in
MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
seal.fulfill(())

@ -16,7 +16,7 @@ public final class OpenGroupManager : OpenGroupManagerProtocol {
private init() { }
public func addOpenGroup(with url: String) -> Promise<Void> {
public func addOpenGroup(with url: String, using transaction: Any) -> Promise<Void> {
guard let url = URL(string: url), let scheme = url.scheme, scheme == "https", url.host != nil else {
return Promise(error: Error.invalidURL)
}
@ -27,10 +27,9 @@ public final class OpenGroupManager : OpenGroupManagerProtocol {
let displayName = profileManager.profileNameForRecipient(withID: userPublicKey)
let profilePictureURL = profileManager.profilePictureURL()
let profileKey = profileManager.localProfileKey().keyData
Storage.writeSync { transaction in
transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: Storage.lastMessageServerIDCollection)
transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: Storage.lastDeletionServerIDCollection)
}
let transaction = transaction as! YapDatabaseReadWriteTransaction
transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: Storage.lastMessageServerIDCollection)
transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: Storage.lastDeletionServerIDCollection)
return PublicChatManager.shared.addChat(server: urlAsString, channel: channelID).done(on: DispatchQueue.main) { _ in
let _ = OpenGroupAPI.setDisplayName(to: displayName, on: urlAsString)
let _ = OpenGroupAPI.setProfilePictureURL(to: profilePictureURL, using: profileKey, on: urlAsString)

Loading…
Cancel
Save