2021-01-13 04:20:12 +01:00
|
|
|
import PromiseKit
|
2022-03-24 00:03:51 +01:00
|
|
|
import SessionMessagingKit
|
2021-01-13 04:08:41 +01:00
|
|
|
|
|
|
|
extension AppDelegate {
|
|
|
|
|
2021-01-13 04:20:12 +01:00
|
|
|
@objc(syncConfigurationIfNeeded)
|
|
|
|
func syncConfigurationIfNeeded() {
|
2021-02-26 05:56:41 +01:00
|
|
|
guard Storage.shared.getUser()?.name != nil else { return }
|
2021-01-13 04:08:41 +01:00
|
|
|
let userDefaults = UserDefaults.standard
|
|
|
|
let lastSync = userDefaults[.lastConfigurationSync] ?? .distantPast
|
2022-03-24 00:03:51 +01:00
|
|
|
guard Date().timeIntervalSince(lastSync) > 7 * 24 * 60 * 60 else { return } // Sync every 2 days
|
2022-02-17 01:45:59 +01:00
|
|
|
|
2022-03-24 00:03:51 +01:00
|
|
|
MessageSender.syncConfiguration(forceSyncNow: false)
|
|
|
|
.done {
|
|
|
|
// Only update the 'lastConfigurationSync' timestamp if we have done the first sync (Don't want
|
|
|
|
// a new device config sync to override config syncs from other devices)
|
|
|
|
if userDefaults[.hasSyncedInitialConfiguration] {
|
|
|
|
userDefaults[.lastConfigurationSync] = Date()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.retainUntilComplete()
|
2021-01-13 04:20:12 +01:00
|
|
|
}
|
2021-05-12 02:33:29 +02:00
|
|
|
|
|
|
|
@objc func startClosedGroupPoller() {
|
|
|
|
guard OWSIdentityManager.shared().identityKeyPair() != nil else { return }
|
|
|
|
ClosedGroupPoller.shared.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func stopClosedGroupPoller() {
|
|
|
|
ClosedGroupPoller.shared.stop()
|
|
|
|
}
|
2021-01-13 04:08:41 +01:00
|
|
|
}
|