From a5676a5bfc7a26eff53089406e04645a6ba9aa72 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 9 Jun 2022 15:11:53 +1000 Subject: [PATCH] fix: closed group polling for hf --- .../Pollers/ClosedGroupPoller.swift | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift index 70a3698fd..c25f6941e 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/ClosedGroupPoller.swift @@ -61,7 +61,16 @@ public final class ClosedGroupPoller : NSObject { // MARK: Private API private func setUpPolling(for groupPublicKey: String) { Threading.pollerQueue.async { - self.poll(groupPublicKey).done(on: Threading.pollerQueue) { [weak self] _ in + let promises: [Promise] = { + if SnodeAPI.hardfork >= 19 && SnodeAPI.softfork >= 1 { + return [ self.poll(groupPublicKey) ] + } + if SnodeAPI.hardfork >= 19 { + return [ self.poll(groupPublicKey, defaultInbox: true), self.poll(groupPublicKey) ] + } + return [ self.poll(groupPublicKey, defaultInbox: true) ] + }() + when(resolved: promises).done(on: Threading.pollerQueue) { [weak self] _ in self?.pollRecursively(groupPublicKey) }.catch(on: Threading.pollerQueue) { [weak self] error in // The error is logged in poll(_:) @@ -87,13 +96,15 @@ public final class ClosedGroupPoller : NSObject { timers[groupPublicKey] = Timer.scheduledTimerOnMainThread(withTimeInterval: nextPollInterval, repeats: false) { [weak self] timer in timer.invalidate() Threading.pollerQueue.async { - var promises: [Promise] = [] - if SnodeAPI.hardfork <= 19, SnodeAPI.softfork == 0, let promise = self?.poll(groupPublicKey, defaultInbox: true) { - promises.append(promise) - } - if SnodeAPI.hardfork >= 19, SnodeAPI.softfork >= 0,let promise = self?.poll(groupPublicKey) { - promises.append(promise) - } + let promises: [Promise] = { + if SnodeAPI.hardfork >= 19 && SnodeAPI.softfork >= 1 { + return [ self?.poll(groupPublicKey) ].compactMap{ $0 } + } + if SnodeAPI.hardfork >= 19 { + return [ self?.poll(groupPublicKey, defaultInbox: true), self?.poll(groupPublicKey) ].compactMap{ $0 } + } + return [ self?.poll(groupPublicKey, defaultInbox: true) ].compactMap{ $0 } + }() when(resolved: promises).done(on: Threading.pollerQueue) { _ in self?.pollRecursively(groupPublicKey) }.catch(on: Threading.pollerQueue) { error in