mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 12:28:24 +00:00
Improve performance
This commit is contained in:
parent
fda66d3f5d
commit
4d44bed67d
@ -26,7 +26,7 @@ class ClosedGroupPoller {
|
||||
|
||||
// region Settings
|
||||
companion object {
|
||||
private val pollInterval: Long = 2 * 1000
|
||||
private val pollInterval: Long = 6 * 1000
|
||||
}
|
||||
// endregion
|
||||
|
||||
@ -57,7 +57,8 @@ class ClosedGroupPoller {
|
||||
// region Private API
|
||||
private fun poll(): List<Promise<Unit, Exception>> {
|
||||
if (!isPolling) { return listOf() }
|
||||
val publicKeys = MessagingModuleConfiguration.shared.storage.getAllActiveClosedGroupPublicKeys()
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val publicKeys = storage.getAllActiveClosedGroupPublicKeys()
|
||||
return publicKeys.map { publicKey ->
|
||||
val promise = SnodeAPI.getSwarm(publicKey).bind { swarm ->
|
||||
val snode = swarm.getRandomElementOrNull() ?: throw InsufficientSnodesException() // Should be cryptographically secure
|
||||
@ -65,10 +66,7 @@ class ClosedGroupPoller {
|
||||
SnodeAPI.getRawMessages(snode, publicKey).map {SnodeAPI.parseRawMessagesResponse(it, snode, publicKey) }
|
||||
}
|
||||
promise.successBackground { messages ->
|
||||
if (!MessagingModuleConfiguration.shared.storage.isGroupActive(publicKey)) {
|
||||
// ignore inactive group's messages
|
||||
return@successBackground
|
||||
}
|
||||
if (!storage.isGroupActive(publicKey)) { return@successBackground }
|
||||
messages.forEach { envelope ->
|
||||
val job = MessageReceiveJob(envelope.toByteArray())
|
||||
JobQueue.shared.add(job)
|
||||
@ -77,7 +75,7 @@ class ClosedGroupPoller {
|
||||
promise.fail {
|
||||
Log.d("Loki", "Polling failed for closed group with public key: $publicKey due to error: $it.")
|
||||
}
|
||||
promise.map { Unit }
|
||||
promise.map { }
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
|
@ -18,7 +18,7 @@ class Poller {
|
||||
var userPublicKey = MessagingModuleConfiguration.shared.storage.getUserPublicKey() ?: ""
|
||||
private var hasStarted: Boolean = false
|
||||
private val usedSnodes: MutableSet<Snode> = mutableSetOf()
|
||||
public var isCaughtUp = false
|
||||
var isCaughtUp = false
|
||||
|
||||
// region Settings
|
||||
companion object {
|
||||
|
Loading…
x
Reference in New Issue
Block a user