From f59816af7d7137f3854a3f38f7d2dfca074c9a1e Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 17 Jun 2020 16:57:49 +1000 Subject: [PATCH] Fix open group polling --- .../Open Groups/LokiPublicChatPoller.swift | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/Open Groups/LokiPublicChatPoller.swift b/SignalServiceKit/src/Loki/API/Open Groups/LokiPublicChatPoller.swift index fa0194169..3d8ac61d0 100644 --- a/SignalServiceKit/src/Loki/API/Open Groups/LokiPublicChatPoller.swift +++ b/SignalServiceKit/src/Loki/API/Open Groups/LokiPublicChatPoller.swift @@ -25,16 +25,19 @@ public final class LokiPublicChatPoller : NSObject { @objc public func startIfNeeded() { if hasStarted { return } - pollForNewMessagesTimer = Timer.scheduledTimer(withTimeInterval: pollForNewMessagesInterval, repeats: true) { [weak self] _ in self?.pollForNewMessages() } - pollForDeletedMessagesTimer = Timer.scheduledTimer(withTimeInterval: pollForDeletedMessagesInterval, repeats: true) { [weak self] _ in self?.pollForDeletedMessages() } - pollForModeratorsTimer = Timer.scheduledTimer(withTimeInterval: pollForModeratorsInterval, repeats: true) { [weak self] _ in self?.pollForModerators() } - pollForDisplayNamesTimer = Timer.scheduledTimer(withTimeInterval: pollForDisplayNamesInterval, repeats: true) { [weak self] _ in self?.pollForDisplayNames() } - // Perform initial updates - pollForNewMessages() - pollForDeletedMessages() - pollForModerators() - pollForDisplayNames() - hasStarted = true + DispatchQueue.main.async { [weak self] in // Timers don't do well on background queues + guard let strongSelf = self else { return } + strongSelf.pollForNewMessagesTimer = Timer.scheduledTimer(withTimeInterval: strongSelf.pollForNewMessagesInterval, repeats: true) { _ in self?.pollForNewMessages() } + strongSelf.pollForDeletedMessagesTimer = Timer.scheduledTimer(withTimeInterval: strongSelf.pollForDeletedMessagesInterval, repeats: true) { _ in self?.pollForDeletedMessages() } + strongSelf.pollForModeratorsTimer = Timer.scheduledTimer(withTimeInterval: strongSelf.pollForModeratorsInterval, repeats: true) { _ in self?.pollForModerators() } + strongSelf.pollForDisplayNamesTimer = Timer.scheduledTimer(withTimeInterval: strongSelf.pollForDisplayNamesInterval, repeats: true) { _ in self?.pollForDisplayNames() } + // Perform initial updates + strongSelf.pollForNewMessages() + strongSelf.pollForDeletedMessages() + strongSelf.pollForModerators() + strongSelf.pollForDisplayNames() + strongSelf.hasStarted = true + } } @objc public func stop() {