|
|
@ -58,12 +58,16 @@ public final class ClosedGroupPoller : NSObject {
|
|
|
|
// MARK: Private API
|
|
|
|
// MARK: Private API
|
|
|
|
private func setUpPolling(for groupPublicKey: String) {
|
|
|
|
private func setUpPolling(for groupPublicKey: String) {
|
|
|
|
poll(groupPublicKey).done2 { [weak self] _ in
|
|
|
|
poll(groupPublicKey).done2 { [weak self] _ in
|
|
|
|
|
|
|
|
DispatchQueue.main.async { // Timers don't do well on background queues
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
}.catch2 { [weak self] error in
|
|
|
|
}.catch2 { [weak self] error in
|
|
|
|
// The error is logged in poll(_:isBackgroundPoll:)
|
|
|
|
// The error is logged in poll(_:)
|
|
|
|
|
|
|
|
DispatchQueue.main.async { // Timers don't do well on background queues
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func pollRecursively(_ groupPublicKey: String) {
|
|
|
|
private func pollRecursively(_ groupPublicKey: String) {
|
|
|
|
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
|
|
|
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
|
|
|
@ -82,13 +86,17 @@ public final class ClosedGroupPoller : NSObject {
|
|
|
|
timers[groupPublicKey] = Timer.scheduledTimer(withTimeInterval: nextPollInterval, repeats: false) { [weak self] timer in
|
|
|
|
timers[groupPublicKey] = Timer.scheduledTimer(withTimeInterval: nextPollInterval, repeats: false) { [weak self] timer in
|
|
|
|
timer.invalidate()
|
|
|
|
timer.invalidate()
|
|
|
|
self?.poll(groupPublicKey).done2 { _ in
|
|
|
|
self?.poll(groupPublicKey).done2 { _ in
|
|
|
|
|
|
|
|
DispatchQueue.main.async { // Timers don't do well on background queues
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
}.catch2 { error in
|
|
|
|
}.catch2 { error in
|
|
|
|
// The error is logged in poll(_:)
|
|
|
|
// The error is logged in poll(_:)
|
|
|
|
|
|
|
|
DispatchQueue.main.async { // Timers don't do well on background queues
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
self?.pollRecursively(groupPublicKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func poll(_ groupPublicKey: String) -> Promise<Void> {
|
|
|
|
private func poll(_ groupPublicKey: String) -> Promise<Void> {
|
|
|
|
guard isPolling(for: groupPublicKey) else { return Promise.value(()) }
|
|
|
|
guard isPolling(for: groupPublicKey) else { return Promise.value(()) }
|
|
|
|