Merge pull request #4029 from element-hq/feature/bma/eventCache

Add a feature flag to be able to enable the event cache
This commit is contained in:
Benoit Marty 2024-12-12 17:59:47 +01:00 committed by GitHub
commit ecc308a9d7
11 changed files with 56 additions and 4 deletions

View file

@ -61,6 +61,10 @@ fun RoomListContextMenu(
onFavoriteChange = { isFavorite -> onFavoriteChange = { isFavorite ->
eventSink(RoomListEvents.SetRoomIsFavorite(contextMenu.roomId, isFavorite)) eventSink(RoomListEvents.SetRoomIsFavorite(contextMenu.roomId, isFavorite))
}, },
onClearCacheRoomClick = {
eventSink(RoomListEvents.HideContextMenu)
eventSink(RoomListEvents.ClearCacheOfRoom(contextMenu.roomId))
},
) )
} }
} }
@ -73,6 +77,7 @@ private fun RoomListModalBottomSheetContent(
onFavoriteChange: (isFavorite: Boolean) -> Unit, onFavoriteChange: (isFavorite: Boolean) -> Unit,
onRoomMarkReadClick: () -> Unit, onRoomMarkReadClick: () -> Unit,
onRoomMarkUnreadClick: () -> Unit, onRoomMarkUnreadClick: () -> Unit,
onClearCacheRoomClick: () -> Unit,
) { ) {
Column( Column(
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
@ -177,6 +182,18 @@ private fun RoomListModalBottomSheetContent(
), ),
style = ListItemStyle.Destructive, style = ListItemStyle.Destructive,
) )
if (contextMenu.eventCacheFeatureFlagEnabled) {
ListItem(
headlineContent = {
Text(text = "Clear cache for this room")
},
modifier = Modifier.clickable { onClearCacheRoomClick() },
leadingContent = ListItemContent.Icon(
iconSource = IconSource.Vector(CompoundIcons.Delete())
),
style = ListItemStyle.Primary,
)
}
} }
} }
@ -195,5 +212,6 @@ internal fun RoomListModalBottomSheetContentPreview(
onRoomSettingsClick = {}, onRoomSettingsClick = {},
onLeaveRoomClick = {}, onLeaveRoomClick = {},
onFavoriteChange = {}, onFavoriteChange = {},
onClearCacheRoomClick = {},
) )
} }

View file

@ -25,4 +25,5 @@ sealed interface RoomListEvents {
data class MarkAsRead(val roomId: RoomId) : ContextMenuEvents data class MarkAsRead(val roomId: RoomId) : ContextMenuEvents
data class MarkAsUnread(val roomId: RoomId) : ContextMenuEvents data class MarkAsUnread(val roomId: RoomId) : ContextMenuEvents
data class SetRoomIsFavorite(val roomId: RoomId, val isFavorite: Boolean) : ContextMenuEvents data class SetRoomIsFavorite(val roomId: RoomId, val isFavorite: Boolean) : ContextMenuEvents
data class ClearCacheOfRoom(val roomId: RoomId) : ContextMenuEvents
} }

View file

@ -146,6 +146,7 @@ class RoomListPresenter @Inject constructor(
AcceptDeclineInviteEvents.DeclineInvite(event.roomListRoomSummary.toInviteData()) AcceptDeclineInviteEvents.DeclineInvite(event.roomListRoomSummary.toInviteData())
) )
} }
is RoomListEvents.ClearCacheOfRoom -> coroutineScope.clearCacheOfRoom(event.roomId)
} }
} }
@ -255,7 +256,8 @@ class RoomListPresenter @Inject constructor(
isDm = event.roomListRoomSummary.isDm, isDm = event.roomListRoomSummary.isDm,
isFavorite = event.roomListRoomSummary.isFavorite, isFavorite = event.roomListRoomSummary.isFavorite,
markAsUnreadFeatureFlagEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.MarkAsUnread), markAsUnreadFeatureFlagEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.MarkAsUnread),
hasNewContent = event.roomListRoomSummary.hasNewContent hasNewContent = event.roomListRoomSummary.hasNewContent,
eventCacheFeatureFlagEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.EventCache),
) )
contextMenuState.value = initialState contextMenuState.value = initialState
@ -312,6 +314,12 @@ class RoomListPresenter @Inject constructor(
} }
} }
private fun CoroutineScope.clearCacheOfRoom(roomId: RoomId) = launch {
client.getRoom(roomId)?.use { room ->
room.clearEventCacheStorage()
}
}
/** /**
* Checks if the user needs to migrate to a native sliding sync version. * Checks if the user needs to migrate to a native sliding sync version.
*/ */

View file

@ -46,6 +46,7 @@ data class RoomListState(
val isDm: Boolean, val isDm: Boolean,
val isFavorite: Boolean, val isFavorite: Boolean,
val markAsUnreadFeatureFlagEnabled: Boolean, val markAsUnreadFeatureFlagEnabled: Boolean,
val eventCacheFeatureFlagEnabled: Boolean,
val hasNewContent: Boolean, val hasNewContent: Boolean,
) : ContextMenu ) : ContextMenu
} }

View file

@ -31,4 +31,5 @@ internal fun aContextMenuShown(
markAsUnreadFeatureFlagEnabled = true, markAsUnreadFeatureFlagEnabled = true,
hasNewContent = hasNewContent, hasNewContent = hasNewContent,
isFavorite = isFavorite, isFavorite = isFavorite,
eventCacheFeatureFlagEnabled = false,
) )

View file

@ -288,6 +288,7 @@ class RoomListPresenterTest {
isDm = false, isDm = false,
isFavorite = false, isFavorite = false,
markAsUnreadFeatureFlagEnabled = true, markAsUnreadFeatureFlagEnabled = true,
eventCacheFeatureFlagEnabled = false,
hasNewContent = false, hasNewContent = false,
) )
) )
@ -305,6 +306,7 @@ class RoomListPresenterTest {
isDm = false, isDm = false,
isFavorite = true, isFavorite = true,
markAsUnreadFeatureFlagEnabled = true, markAsUnreadFeatureFlagEnabled = true,
eventCacheFeatureFlagEnabled = false,
hasNewContent = false, hasNewContent = false,
) )
) )
@ -335,6 +337,7 @@ class RoomListPresenterTest {
isDm = false, isDm = false,
isFavorite = false, isFavorite = false,
markAsUnreadFeatureFlagEnabled = true, markAsUnreadFeatureFlagEnabled = true,
eventCacheFeatureFlagEnabled = false,
hasNewContent = false, hasNewContent = false,
) )
) )

View file

@ -161,4 +161,11 @@ enum class FeatureFlags(
defaultValue = { buildMeta -> buildMeta.buildType != BuildType.RELEASE }, defaultValue = { buildMeta -> buildMeta.buildType != BuildType.RELEASE },
isFinished = false, isFinished = false,
), ),
EventCache(
key = "feature.event_cache",
title = "Use SDK Event cache",
description = "Warning: you must kill and restart the app for the change to take effect.",
defaultValue = { false },
isFinished = false,
),
} }

View file

@ -232,6 +232,11 @@ interface MatrixRoom : Closeable {
*/ */
suspend fun setUnreadFlag(isUnread: Boolean): Result<Unit> suspend fun setUnreadFlag(isUnread: Boolean): Result<Unit>
/**
* Clear the event cache storage for the current room.
*/
suspend fun clearEventCacheStorage(): Result<Unit>
/** /**
* Share a location message in the room. * Share a location message in the room.
* *

View file

@ -109,9 +109,7 @@ class RustMatrixClientFactory @Inject constructor(
.addRootCertificates(userCertificatesProvider.provides()) .addRootCertificates(userCertificatesProvider.provides())
.autoEnableBackups(true) .autoEnableBackups(true)
.autoEnableCrossSigning(true) .autoEnableCrossSigning(true)
// TODO Add a feature flag to enable persistent storage .useEventCachePersistentStorage(featureFlagService.isFeatureEnabled(FeatureFlags.EventCache))
// See https://github.com/matrix-org/matrix-rust-sdk/pull/4396
.useEventCachePersistentStorage(false)
.roomKeyRecipientStrategy( .roomKeyRecipientStrategy(
strategy = if (featureFlagService.isFeatureEnabled(FeatureFlags.OnlySignedDeviceIsolationMode)) { strategy = if (featureFlagService.isFeatureEnabled(FeatureFlags.OnlySignedDeviceIsolationMode)) {
CollectStrategy.IdentityBasedStrategy CollectStrategy.IdentityBasedStrategy

View file

@ -569,6 +569,12 @@ class RustMatrixRoom(
} }
} }
override suspend fun clearEventCacheStorage(): Result<Unit> = withContext(roomDispatcher) {
runCatching {
innerRoom.clearEventCacheStorage()
}
}
override suspend fun kickUser(userId: UserId, reason: String?): Result<Unit> = withContext(roomDispatcher) { override suspend fun kickUser(userId: UserId, reason: String?): Result<Unit> = withContext(roomDispatcher) {
runCatching { runCatching {
innerRoom.kickUser(userId.value, reason) innerRoom.kickUser(userId.value, reason)

View file

@ -574,6 +574,10 @@ class FakeMatrixRoom(
fun givenRoomMembersState(state: MatrixRoomMembersState) { fun givenRoomMembersState(state: MatrixRoomMembersState) {
membersStateFlow.value = state membersStateFlow.value = state
} }
override suspend fun clearEventCacheStorage(): Result<Unit> {
return Result.success(Unit)
}
} }
fun defaultRoomPowerLevels() = MatrixRoomPowerLevels( fun defaultRoomPowerLevels() = MatrixRoomPowerLevels(