diff --git a/app/src/main/kotlin/io/element/android/x/di/DefaultSessionGraphFactory.kt b/app/src/main/kotlin/io/element/android/x/di/DefaultSessionGraphFactory.kt index 9631713bb6..5bfe082ffe 100644 --- a/app/src/main/kotlin/io/element/android/x/di/DefaultSessionGraphFactory.kt +++ b/app/src/main/kotlin/io/element/android/x/di/DefaultSessionGraphFactory.kt @@ -15,7 +15,7 @@ import io.element.android.libraries.matrix.api.MatrixClient @ContributesBinding(AppScope::class) class DefaultSessionGraphFactory( - private val appGraph: AppGraph + private val appGraph: AppGraph, ) : SessionGraphFactory { override fun create(client: MatrixClient): Any { return appGraph.sessionGraphFactory.create(client) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiverHandler.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiverHandler.kt index cb9ef8c82d..8dedb3325c 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiverHandler.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiverHandler.kt @@ -105,13 +105,21 @@ class NotificationBroadcastReceiverHandler( @Suppress("unused") private fun handleMarkAsRead(sessionId: SessionId, roomId: RoomId, threadId: ThreadId?) = appCoroutineScope.launch { val client = matrixClientProvider.getOrRestore(sessionId).getOrNull() ?: return@launch - val isSendPublicReadReceiptsEnabled = sessionPreferencesStore.get(sessionId, this).isSendPublicReadReceiptsEnabled().first() + val isSendPublicReadReceiptsEnabled = sessionPreferencesStore.get( + sessionId = sessionId, + // Make sure `sessionCoroutineScope` is used here, otherwise we'll have several instances using different coroutines, + // and it will not work as expected. + sessionCoroutineScope = client.sessionCoroutineScope, + ).isSendPublicReadReceiptsEnabled().first() val receiptType = if (isSendPublicReadReceiptsEnabled) { ReceiptType.READ } else { ReceiptType.READ_PRIVATE } - val room = client.getJoinedRoom(roomId) ?: return@launch + + val (room, needsDestroy) = activeRoomsHolder.getActiveRoomMatching(sessionId, roomId)?.let { it to false } + ?: client.getJoinedRoom(roomId)?.let { it to true } + ?: return@launch val timeline = if (threadId != null) { room.createTimeline(CreateTimelineParams.Threaded(threadId)).getOrNull() } else { @@ -131,6 +139,10 @@ class NotificationBroadcastReceiverHandler( if (timeline?.mode != Timeline.Mode.Live) { timeline?.close() } + + if (needsDestroy) { + room.destroy() + } } private fun handleSmartReply(