|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|