mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.1 KiB
Swift
31 lines
1.1 KiB
Swift
5 years ago
|
import PromiseKit
|
||
|
|
||
|
@objc(LKBackgroundPoller)
|
||
|
public final class BackgroundPoller : NSObject {
|
||
5 years ago
|
private static var closedGroupPoller: ClosedGroupPoller!
|
||
5 years ago
|
|
||
|
private override init() { }
|
||
|
|
||
|
@objc(pollWithCompletionHandler:)
|
||
|
public static func poll(completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
||
|
var promises: [Promise<Void>] = []
|
||
|
promises.append(AppEnvironment.shared.messageFetcherJob.run()) // FIXME: It'd be nicer to just use Poller directly
|
||
5 years ago
|
closedGroupPoller = ClosedGroupPoller()
|
||
|
promises.append(contentsOf: closedGroupPoller.pollOnce())
|
||
5 years ago
|
var openGroups: [String:OpenGroup] = [:]
|
||
5 years ago
|
Storage.read { transaction in
|
||
|
openGroups = LokiDatabaseUtilities.getAllPublicChats(in: transaction)
|
||
|
}
|
||
|
openGroups.values.forEach { openGroup in
|
||
|
let poller = PublicChatPoller(for: openGroup)
|
||
|
poller.stop()
|
||
|
promises.append(poller.pollForNewMessages())
|
||
|
}
|
||
|
when(resolved: promises).done { _ in
|
||
|
completionHandler(.newData)
|
||
|
}.catch { _ in
|
||
|
completionHandler(.failed)
|
||
|
}
|
||
|
}
|
||
|
}
|