mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-03 21:52:21 +00:00
Actively poll public chat group if the app is in the foreground
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.loki
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import org.thoughtcrime.securesms.jobs.PushDecryptJob
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
@@ -10,10 +11,33 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI
|
||||
|
||||
object LokiGroupChatPoller {
|
||||
class LokiGroupChatPoller(private val context: Context, private val groupID: Long) {
|
||||
private val handler = Handler()
|
||||
private var hasStarted = false
|
||||
|
||||
@JvmStatic
|
||||
fun poll(context: Context, groupID: Long) {
|
||||
private val task = object : Runnable {
|
||||
|
||||
override fun run() {
|
||||
poll()
|
||||
handler.postDelayed(this, pollInterval)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val pollInterval: Long = 5 * 1000
|
||||
}
|
||||
|
||||
fun startIfNeeded() {
|
||||
if (hasStarted) return
|
||||
task.run()
|
||||
hasStarted = true
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
handler.removeCallbacks(task)
|
||||
}
|
||||
|
||||
private fun poll() {
|
||||
LokiGroupChatAPI.getMessages(groupID).success { messages ->
|
||||
messages.map { message ->
|
||||
val id = "loki-group-chat-$groupID".toByteArray()
|
||||
|
||||
Reference in New Issue
Block a user