Force sync configuration upon enabling multi device or clearing data

pull/333/head
nielsandriesse 4 years ago
parent 9eefc21eb9
commit 3ec4e0ae52

@ -1,7 +1,9 @@
import PromiseKit
extension AppDelegate {
@objc func syncConfigurationIfNeeded() {
@objc(syncConfigurationIfNeeded)
func syncConfigurationIfNeeded() {
let userDefaults = UserDefaults.standard
guard userDefaults[.isUsingMultiDevice] else { return }
let lastSync = userDefaults[.lastConfigurationSync] ?? .distantPast
@ -13,4 +15,20 @@ extension AppDelegate {
JobQueue.shared.add(job, using: transaction)
}
}
func forceSyncConfigurationNowIfNeeded() -> Promise<Void> {
let userDefaults = UserDefaults.standard
guard userDefaults[.isUsingMultiDevice] else { return Promise.value(()) }
let configurationMessage = ConfigurationMessage.getCurrent()
let destination = Message.Destination.contact(publicKey: getUserHexEncodedPublicKey())
let (promise, seal) = Promise<Void>.pending()
Storage.write { transaction in
MessageSender.send(configurationMessage, to: destination, using: transaction).done {
seal.fulfill(())
}.catch { _ in
seal.fulfill(()) // Fulfill even if this failed; the configuration in the swarm should be at most 2 days old
}.retainUntilComplete()
}
return promise
}
}

@ -148,6 +148,9 @@ final class MultiDeviceVC : BaseVC {
// MARK: Interaction
@objc private func handleToggle() {
stepsRow.isHidden = !toggle.isOn
UserDefaults.standard[.isUsingMultiDevice] = toggle.isOn
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete()
}
@objc private func copyMnemonic() {

@ -50,8 +50,14 @@ final class NukeDataModal : Modal {
// MARK: Interaction
@objc private func nuke() {
func proceed() {
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, 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
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
}.retainUntilComplete()
}
}
if KeyPairUtilities.hasV2KeyPair() {
proceed()

Loading…
Cancel
Save