From 7cc60e61735b927f4520ef54860b869be03b5338 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 26 Jun 2020 16:17:15 +1000 Subject: [PATCH] add flag in public chat poller for catching up --- .../loki/api/LokiPublicChatManager.kt | 18 ++++++++++++++++++ .../securesms/loki/api/LokiPublicChatPoller.kt | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatManager.kt b/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatManager.kt index 29b6feac52..93f1bfc7a1 100644 --- a/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatManager.kt +++ b/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatManager.kt @@ -20,6 +20,24 @@ class LokiPublicChatManager(private val context: Context) { private val observers = mutableMapOf() private var isPolling = false + public fun isAllCatchUp():Boolean { + var isAllCatchUp = true + refreshChatsAndPollers() + for ((threadId, chat) in chats) { + val poller = pollers[threadId] ?: LokiPublicChatPoller(context, chat) + isAllCatchUp = isAllCatchUp() && poller.isCatchUp() + } + return isAllCatchUp + } + + public fun shouldAllCatchUp() { + refreshChatsAndPollers() + for ((threadId, chat) in chats) { + val poller = pollers[threadId] ?: LokiPublicChatPoller(context, chat) + poller.shouldCatchUp() + } + } + public fun startPollersIfNeeded() { refreshChatsAndPollers() diff --git a/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt b/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt index abefd33c40..0fed922b7c 100644 --- a/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt +++ b/src/org/thoughtcrime/securesms/loki/api/LokiPublicChatPoller.kt @@ -35,6 +35,8 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki private val handler = Handler() private var hasStarted = false + private var isCatchUp = false + // region Convenience private val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) private var displayNameUpdatees = setOf() @@ -82,6 +84,14 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki } // endregion + fun isCatchUp(): Boolean { + return isCatchUp + } + + fun shouldCatchUp() { + isCatchUp = false + } + // region Settings companion object { private val pollForNewMessagesInterval: Long = 4 * 1000 @@ -249,6 +259,7 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki processIncomingMessage(message) } } + isCatchUp = true }.fail { Log.d("Loki", "Failed to get messages for group chat with ID: ${group.channel} on server: ${group.server}.") }