fix: unreads work now for incoming messages, need to sync conv volatile properly still

This commit is contained in:
0x330a
2023-02-20 17:36:35 +11:00
parent 1b580cca1b
commit 8c512c7b6e
8 changed files with 58 additions and 33 deletions

View File

@@ -176,7 +176,7 @@ class BatchMessageReceiveJob(
}
// increment unreads, notify, and update thread
// last seen will be the current last seen if not changed (re-computes the read counts for thread record)
storage.markConversationAsRead(threadId, 0)
storage.markConversationAsRead(threadId, myLastSeen)
storage.updateThread(threadId, true)
SSKEnvironment.shared.notificationManager.updateNotification(context, threadId)
}

View File

@@ -20,7 +20,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
override var failureCount: Int = 0
override val maxFailureCount: Int = 1
override suspend fun execute() {
override suspend fun execute(dispatcherName: String) {
val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair()
val userPublicKey = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
val delegate = delegate
@@ -37,7 +37,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
|| (destination is Destination.Contact && destination.publicKey != userPublicKey)
) {
Log.w(TAG, "No need to run config sync job, TODO")
delegate?.handleJobSucceeded(this)
delegate?.handleJobSucceeded(this, dispatcherName)
return
}
@@ -52,7 +52,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
).filter { config -> config.needsPush() }
// don't run anything if we don't need to push anything
if (configsRequiringPush.isEmpty()) return delegate.handleJobSucceeded(this)
if (configsRequiringPush.isEmpty()) return delegate.handleJobSucceeded(this, dispatcherName)
// allow null results here so the list index matches configsRequiringPush
val batchObjects: List<Pair<SharedConfigurationMessage, SnodeAPI.SnodeBatchRequestInfo>?> = configsRequiringPush.map { config ->
@@ -79,7 +79,7 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
if (batchObjects.any { it == null }) {
// stop running here, something like a signing error occurred
return delegate.handleJobFailedPermanently(this, NullPointerException("One or more requests had a null batch request info"))
return delegate.handleJobFailedPermanently(this, dispatcherName, NullPointerException("One or more requests had a null batch request info"))
}
val allRequests = mutableListOf<SnodeAPI.SnodeBatchRequestInfo>()
@@ -145,9 +145,9 @@ data class ConfigurationSyncJob(val destination: Destination): Job {
}
} catch (e: Exception) {
Log.e(TAG, "Error performing batch request", e)
return delegate.handleJobFailedPermanently(this, e)
return delegate.handleJobFailedPermanently(this, dispatcherName, e)
}
delegate.handleJobSucceeded(this)
delegate.handleJobSucceeded(this, dispatcherName)
}
fun Destination.destinationPublicKey(): String = when (this) {

View File

@@ -26,6 +26,7 @@ import org.session.libsession.snode.RawResponse
import org.session.libsession.snode.SnodeAPI
import org.session.libsession.snode.SnodeModule
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.WindowDebouncer
import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.Namespace
import org.session.libsignal.utilities.Snode
@@ -35,12 +36,14 @@ import java.util.TimerTask
private class PromiseCanceledException : Exception("Promise canceled.")
class Poller(private val configFactory: ConfigFactoryProtocol) {
class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Timer) {
var userPublicKey = MessagingModuleConfiguration.shared.storage.getUserPublicKey() ?: ""
private var hasStarted: Boolean = false
private val usedSnodes: MutableSet<Snode> = mutableSetOf()
var isCaughtUp = false
var configPollingJob: Job? = null
val configDebouncer = WindowDebouncer(3000, debounceTimer)
// region Settings
companion object {
@@ -208,10 +211,12 @@ class Poller(private val configFactory: ConfigFactoryProtocol) {
if (key == Namespace.DEFAULT) {
processPersonalMessages(snode, body)
} else {
when (ConfigBase.kindFor(key)) {
UserProfile::class.java -> processConfig(snode, body, key, configFactory.user)
Contacts::class.java -> processConfig(snode, body, key, configFactory.contacts)
ConversationVolatileConfig::class.java -> processConfig(snode, body, key, configFactory.convoVolatile)
configDebouncer.publish {
when (ConfigBase.kindFor(key)) {
UserProfile::class.java -> processConfig(snode, body, key, configFactory.user)
Contacts::class.java -> processConfig(snode, body, key, configFactory.contacts)
ConversationVolatileConfig::class.java -> processConfig(snode, body, key, configFactory.convoVolatile)
}
}
}
}