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

@ -132,20 +132,22 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
} }
isJoining = true isJoining = true
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in
OpenGroupManager.shared.addOpenGroup(with: urlAsString) Storage.shared.write { transaction in
.done(on: DispatchQueue.main) { [weak self] _ in OpenGroupManager.shared.addOpenGroup(with: urlAsString, using: transaction)
self?.presentingViewController!.dismiss(animated: true, completion: nil) .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 .catch(on: DispatchQueue.main) { [weak self] error in
var title = "Couldn't Join" self?.dismiss(animated: true, completion: nil) // Dismiss the loader
var message = "" var title = "Couldn't Join"
if case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, _) = error, statusCode == 401 || statusCode == 403 { var message = ""
title = "Unauthorized" if case OnionRequestAPI.Error.httpRequestFailedAtDestination(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
message = "Please ask the open group operator to add you to the group." 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 = { private lazy var toggle: UISwitch = {
let result = UISwitch() let result = UISwitch()
result.onTintColor = Colors.accent result.onTintColor = Colors.accent
result.isOn = UserDefaults.standard[.isUsingMultiDevice]
return result return result
}() }()

@ -51,7 +51,7 @@ final class NukeDataModal : Modal {
@objc private func nuke() { @objc private func nuke() {
func proceed() { func proceed() {
let appDelegate = UIApplication.shared.delegate as! AppDelegate 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) { appDelegate.forceSyncConfigurationNowIfNeeded().done(on: DispatchQueue.main) {
self?.dismiss(animated: true, completion: nil) // Dismiss the loader 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 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 { 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) let allOpenGroups = Set(storage.getAllUserOpenGroups().keys)
for openGroupURL in message.openGroups { for openGroupURL in message.openGroups {
guard !allOpenGroups.contains(openGroupURL) else { continue } 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 // Validate the message
guard message.isValid else { handleFailure(with: Error.invalidMessage, using: transaction); return promise } guard message.isValid else { handleFailure(with: Error.invalidMessage, using: transaction); return promise }
// Stop here if this is a self-send // Stop here if this is a self-send (unless it's a configuration message)
guard !isSelfSend else { guard !isSelfSend || message is ConfigurationMessage else {
storage.write(with: { transaction in storage.write(with: { transaction in
MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction) MessageSender.handleSuccessfulMessageSend(message, to: destination, using: transaction)
seal.fulfill(()) seal.fulfill(())

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

Loading…
Cancel
Save