add flag in public chat poller for catching up

This commit is contained in:
ryanzhao 2020-06-26 16:17:15 +10:00
parent 106c22d9d2
commit 7cc60e6173
2 changed files with 29 additions and 0 deletions

View File

@ -20,6 +20,24 @@ class LokiPublicChatManager(private val context: Context) {
private val observers = mutableMapOf<Long, ContentObserver>()
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()

View File

@ -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<String>()
@ -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}.")
}