From f64eb5218c368a560004ef17c7185c309494a002 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 8 Nov 2023 12:41:15 +0100 Subject: [PATCH] Show full history if key backup is enabled. --- .../android/libraries/matrix/impl/RustMatrixClient.kt | 2 ++ .../libraries/matrix/impl/room/RustMatrixRoom.kt | 2 ++ .../matrix/impl/timeline/RustMatrixTimeline.kt | 2 ++ .../TimelineEncryptedHistoryPostProcessor.kt | 3 ++- .../TimelineEncryptedHistoryPostProcessorTest.kt | 11 +++++++++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt index 99dd0af8fd..035add9ab2 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt @@ -72,6 +72,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout +import org.matrix.rustcomponents.sdk.BackupState import org.matrix.rustcomponents.sdk.Client import org.matrix.rustcomponents.sdk.ClientDelegate import org.matrix.rustcomponents.sdk.NotificationProcessSetup @@ -200,6 +201,7 @@ class RustMatrixClient constructor( cachedPairOfRoom?.let { (roomListItem, fullRoom) -> RustMatrixRoom( sessionId = sessionId, + isKeyBackupEnabled = client.encryption().backupState() == BackupState.ENABLED, roomListItem = roomListItem, innerRoom = fullRoom, roomNotificationSettingsService = notificationSettingsService, diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt index 6e47e90dcd..ab7317590e 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt @@ -86,6 +86,7 @@ import java.io.File @OptIn(ExperimentalCoroutinesApi::class) class RustMatrixRoom( override val sessionId: SessionId, + isKeyBackupEnabled: Boolean, private val roomListItem: RoomListItem, private val innerRoom: Room, private val roomNotificationSettingsService: RustNotificationSettingsService, @@ -126,6 +127,7 @@ class RustMatrixRoom( override val roomNotificationSettingsStateFlow: StateFlow = _roomNotificationSettingsStateFlow override val timeline = RustMatrixTimeline( + isKeyBackupEnabled = isKeyBackupEnabled, matrixRoom = this, innerRoom = innerRoom, roomCoroutineScope = roomCoroutineScope, diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustMatrixTimeline.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustMatrixTimeline.kt index 74ad10ad26..53ae41d887 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustMatrixTimeline.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustMatrixTimeline.kt @@ -57,6 +57,7 @@ private const val INITIAL_MAX_SIZE = 50 class RustMatrixTimeline( roomCoroutineScope: CoroutineScope, + isKeyBackupEnabled: Boolean, private val matrixRoom: MatrixRoom, private val innerRoom: Room, private val dispatcher: CoroutineDispatcher, @@ -77,6 +78,7 @@ class RustMatrixTimeline( private val encryptedHistoryPostProcessor = TimelineEncryptedHistoryPostProcessor( lastLoginTimestamp = lastLoginTimestamp, isRoomEncrypted = matrixRoom.isEncrypted, + isKeyBackupEnabled = isKeyBackupEnabled, paginationStateFlow = _paginationState, dispatcher = dispatcher, ) diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessor.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessor.kt index b273bef21b..60de981780 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessor.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessor.kt @@ -30,12 +30,13 @@ class TimelineEncryptedHistoryPostProcessor( private val dispatcher: CoroutineDispatcher, private val lastLoginTimestamp: Date?, private val isRoomEncrypted: Boolean, + private val isKeyBackupEnabled: Boolean, private val paginationStateFlow: MutableStateFlow, ) { suspend fun process(items: List): List = withContext(dispatcher) { Timber.d("Process on Thread=${Thread.currentThread()}") - if (!isRoomEncrypted || lastLoginTimestamp == null) return@withContext items + if (!isRoomEncrypted || isKeyBackupEnabled || lastLoginTimestamp == null) return@withContext items val filteredItems = replaceWithEncryptionHistoryBannerIfNeeded(items) // Disable back pagination diff --git a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessorTest.kt b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessorTest.kt index 63920cd6ce..d3af9a5670 100644 --- a/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessorTest.kt +++ b/libraries/matrix/impl/src/test/kotlin/io/element/android/libraries/matrix/impl/timeline/postprocessor/TimelineEncryptedHistoryPostProcessorTest.kt @@ -41,6 +41,15 @@ class TimelineEncryptedHistoryPostProcessorTest { assertThat(processor.process(items)).isSameInstanceAs(items) } + @Test + fun `given an encrypted room, and key backup enabled, nothing is done`() = runTest { + val processor = createPostProcessor(isKeyBackupEnabled = true) + val items = listOf( + MatrixTimelineItem.Event(0L, anEventTimelineItem()) + ) + assertThat(processor.process(items)).isSameInstanceAs(items) + } + @Test fun `given a null lastLoginTimestamp, nothing is done`() = runTest { val processor = createPostProcessor(lastLoginTimestamp = null) @@ -108,11 +117,13 @@ class TimelineEncryptedHistoryPostProcessorTest { private fun TestScope.createPostProcessor( lastLoginTimestamp: Date? = defaultLastLoginTimestamp, isRoomEncrypted: Boolean = true, + isKeyBackupEnabled: Boolean = false, paginationStateFlow: MutableStateFlow = MutableStateFlow(MatrixTimeline.PaginationState(hasMoreToLoadBackwards = true, isBackPaginating = false)) ) = TimelineEncryptedHistoryPostProcessor( lastLoginTimestamp = lastLoginTimestamp, isRoomEncrypted = isRoomEncrypted, + isKeyBackupEnabled = isKeyBackupEnabled, paginationStateFlow = paginationStateFlow, dispatcher = StandardTestDispatcher(testScheduler) )