Fix sliding sync loop restarts due to expirations

Both `NotifiableEventResolver` and `DefaultNotificationDrawerManager` were creating new Rust SDK Clients while processing notifications instead of reusing the already existing one.
This commit is contained in:
Jorge Martín 2023-07-17 08:05:12 +02:00
parent 1c15db2686
commit 0632d01d86
6 changed files with 96 additions and 70 deletions

View file

@ -16,6 +16,7 @@
package io.element.android.libraries.push.impl.notifications
import io.element.android.libraries.matrix.ui.di.MatrixClientsHolder
import io.element.android.libraries.androidutils.throttler.FirstThrottler
import io.element.android.libraries.core.cache.CircularCache
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
@ -60,6 +61,7 @@ class DefaultNotificationDrawerManager @Inject constructor(
private val dispatchers: CoroutineDispatchers,
private val buildMeta: BuildMeta,
private val matrixAuthenticationService: MatrixAuthenticationService,
private val matrixClientsHolder: MatrixClientsHolder,
) : NotificationDrawerManager {
/**
* Lazily initializes the NotificationState as we rely on having a current session in order to fetch the persisted queue of events.
@ -255,7 +257,7 @@ class DefaultNotificationDrawerManager @Inject constructor(
val currentUser = tryOrNull(
onError = { Timber.e(it, "Unable to retrieve info for user ${sessionId.value}") },
operation = {
val client = matrixAuthenticationService.restoreSession(sessionId).getOrNull()
val client = matrixClientsHolder.getOrNull(sessionId)
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash
val myUserDisplayName = client?.loadUserDisplayName()?.getOrNull() ?: sessionId.value

View file

@ -16,6 +16,7 @@
package io.element.android.libraries.push.impl.notifications
import io.element.android.libraries.matrix.ui.di.MatrixClientsHolder
import io.element.android.libraries.core.log.logger.LoggerTag
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.matrix.api.auth.MatrixAuthenticationService
@ -62,12 +63,13 @@ class NotifiableEventResolver @Inject constructor(
private val matrixAuthenticationService: MatrixAuthenticationService,
private val buildMeta: BuildMeta,
private val clock: SystemClock,
private val matrixClientsHolder: MatrixClientsHolder,
) {
suspend fun resolveEvent(sessionId: SessionId, roomId: RoomId, eventId: EventId): NotifiableEvent? {
// Restore session
val session = matrixAuthenticationService.restoreSession(sessionId).getOrNull() ?: return null
val notificationService = session.notificationService()
val client = matrixClientsHolder.getOrNull(sessionId) ?: return null
val notificationService = client.notificationService()
val notificationData = notificationService.getNotification(
userId = sessionId,
roomId = roomId,