2022-04-01 08:22:45 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
2021-01-13 04:20:12 +01:00
|
|
|
import PromiseKit
|
2022-03-24 00:03:51 +01:00
|
|
|
import SessionMessagingKit
|
2022-04-01 08:22:45 +02:00
|
|
|
import SessionUtilitiesKit
|
2021-01-13 04:08:41 +01:00
|
|
|
|
|
|
|
extension AppDelegate {
|
|
|
|
|
2021-01-13 04:20:12 +01:00
|
|
|
@objc(syncConfigurationIfNeeded)
|
|
|
|
func syncConfigurationIfNeeded() {
|
2022-04-06 07:43:26 +02:00
|
|
|
let lastSync: Date = (UserDefaults.standard[.lastConfigurationSync] ?? .distantPast)
|
2022-02-17 01:45:59 +01:00
|
|
|
|
2022-04-06 07:43:26 +02:00
|
|
|
guard Date().timeIntervalSince(lastSync) > (7 * 24 * 60 * 60) else { return } // Sync every 2 days
|
|
|
|
|
|
|
|
GRDBStorage.shared.write { db in
|
|
|
|
MessageSender.syncConfiguration(db, 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.standard[.hasSyncedInitialConfiguration] {
|
|
|
|
UserDefaults.standard[.lastConfigurationSync] = Date()
|
|
|
|
}
|
2022-03-24 00:03:51 +01:00
|
|
|
}
|
2022-04-06 07:43:26 +02:00
|
|
|
.retainUntilComplete()
|
|
|
|
}
|
2021-01-13 04:20:12 +01:00
|
|
|
}
|
2021-05-12 02:33:29 +02:00
|
|
|
|
|
|
|
@objc func startClosedGroupPoller() {
|
2022-04-06 07:43:26 +02:00
|
|
|
guard Identity.userExists() else { return }
|
2022-04-01 08:22:45 +02:00
|
|
|
|
2021-05-12 02:33:29 +02:00
|
|
|
ClosedGroupPoller.shared.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func stopClosedGroupPoller() {
|
|
|
|
ClosedGroupPoller.shared.stop()
|
|
|
|
}
|
2021-01-13 04:08:41 +01:00
|
|
|
}
|