Skip to content

Commit 01e2ceb

Browse files
authored
Merge pull request #4029 from element-hq/feature/bma/eventCache
Add a feature flag to be able to enable the event cache
2 parents d5b3eea + f4bd047 commit 01e2ceb

File tree

11 files changed

+56
-4
lines changed

11 files changed

+56
-4
lines changed

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListContextMenu.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ fun RoomListContextMenu(
6161
onFavoriteChange = { isFavorite ->
6262
eventSink(RoomListEvents.SetRoomIsFavorite(contextMenu.roomId, isFavorite))
6363
},
64+
onClearCacheRoomClick = {
65+
eventSink(RoomListEvents.HideContextMenu)
66+
eventSink(RoomListEvents.ClearCacheOfRoom(contextMenu.roomId))
67+
},
6468
)
6569
}
6670
}
@@ -73,6 +77,7 @@ private fun RoomListModalBottomSheetContent(
7377
onFavoriteChange: (isFavorite: Boolean) -> Unit,
7478
onRoomMarkReadClick: () -> Unit,
7579
onRoomMarkUnreadClick: () -> Unit,
80+
onClearCacheRoomClick: () -> Unit,
7681
) {
7782
Column(
7883
modifier = Modifier.fillMaxWidth()
@@ -177,6 +182,18 @@ private fun RoomListModalBottomSheetContent(
177182
),
178183
style = ListItemStyle.Destructive,
179184
)
185+
if (contextMenu.eventCacheFeatureFlagEnabled) {
186+
ListItem(
187+
headlineContent = {
188+
Text(text = "Clear cache for this room")
189+
},
190+
modifier = Modifier.clickable { onClearCacheRoomClick() },
191+
leadingContent = ListItemContent.Icon(
192+
iconSource = IconSource.Vector(CompoundIcons.Delete())
193+
),
194+
style = ListItemStyle.Primary,
195+
)
196+
}
180197
}
181198
}
182199

@@ -195,5 +212,6 @@ internal fun RoomListModalBottomSheetContentPreview(
195212
onRoomSettingsClick = {},
196213
onLeaveRoomClick = {},
197214
onFavoriteChange = {},
215+
onClearCacheRoomClick = {},
198216
)
199217
}

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListEvents.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ sealed interface RoomListEvents {
2525
data class MarkAsRead(val roomId: RoomId) : ContextMenuEvents
2626
data class MarkAsUnread(val roomId: RoomId) : ContextMenuEvents
2727
data class SetRoomIsFavorite(val roomId: RoomId, val isFavorite: Boolean) : ContextMenuEvents
28+
data class ClearCacheOfRoom(val roomId: RoomId) : ContextMenuEvents
2829
}

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListPresenter.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class RoomListPresenter @Inject constructor(
146146
AcceptDeclineInviteEvents.DeclineInvite(event.roomListRoomSummary.toInviteData())
147147
)
148148
}
149+
is RoomListEvents.ClearCacheOfRoom -> coroutineScope.clearCacheOfRoom(event.roomId)
149150
}
150151
}
151152

@@ -255,7 +256,8 @@ class RoomListPresenter @Inject constructor(
255256
isDm = event.roomListRoomSummary.isDm,
256257
isFavorite = event.roomListRoomSummary.isFavorite,
257258
markAsUnreadFeatureFlagEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.MarkAsUnread),
258-
hasNewContent = event.roomListRoomSummary.hasNewContent
259+
hasNewContent = event.roomListRoomSummary.hasNewContent,
260+
eventCacheFeatureFlagEnabled = featureFlagService.isFeatureEnabled(FeatureFlags.EventCache),
259261
)
260262
contextMenuState.value = initialState
261263

@@ -312,6 +314,12 @@ class RoomListPresenter @Inject constructor(
312314
}
313315
}
314316

317+
private fun CoroutineScope.clearCacheOfRoom(roomId: RoomId) = launch {
318+
client.getRoom(roomId)?.use { room ->
319+
room.clearEventCacheStorage()
320+
}
321+
}
322+
315323
/**
316324
* Checks if the user needs to migrate to a native sliding sync version.
317325
*/

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ data class RoomListState(
4646
val isDm: Boolean,
4747
val isFavorite: Boolean,
4848
val markAsUnreadFeatureFlagEnabled: Boolean,
49+
val eventCacheFeatureFlagEnabled: Boolean,
4950
val hasNewContent: Boolean,
5051
) : ContextMenu
5152
}

features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/RoomListStateContextMenuShownProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ internal fun aContextMenuShown(
3131
markAsUnreadFeatureFlagEnabled = true,
3232
hasNewContent = hasNewContent,
3333
isFavorite = isFavorite,
34+
eventCacheFeatureFlagEnabled = false,
3435
)

features/roomlist/impl/src/test/kotlin/io/element/android/features/roomlist/impl/RoomListPresenterTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class RoomListPresenterTest {
288288
isDm = false,
289289
isFavorite = false,
290290
markAsUnreadFeatureFlagEnabled = true,
291+
eventCacheFeatureFlagEnabled = false,
291292
hasNewContent = false,
292293
)
293294
)
@@ -305,6 +306,7 @@ class RoomListPresenterTest {
305306
isDm = false,
306307
isFavorite = true,
307308
markAsUnreadFeatureFlagEnabled = true,
309+
eventCacheFeatureFlagEnabled = false,
308310
hasNewContent = false,
309311
)
310312
)
@@ -335,6 +337,7 @@ class RoomListPresenterTest {
335337
isDm = false,
336338
isFavorite = false,
337339
markAsUnreadFeatureFlagEnabled = true,
340+
eventCacheFeatureFlagEnabled = false,
338341
hasNewContent = false,
339342
)
340343
)

libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,11 @@ enum class FeatureFlags(
161161
defaultValue = { buildMeta -> buildMeta.buildType != BuildType.RELEASE },
162162
isFinished = false,
163163
),
164+
EventCache(
165+
key = "feature.event_cache",
166+
title = "Use SDK Event cache",
167+
description = "Warning: you must kill and restart the app for the change to take effect.",
168+
defaultValue = { false },
169+
isFinished = false,
170+
),
164171
}

libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/MatrixRoom.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ interface MatrixRoom : Closeable {
232232
*/
233233
suspend fun setUnreadFlag(isUnread: Boolean): Result<Unit>
234234

235+
/**
236+
* Clear the event cache storage for the current room.
237+
*/
238+
suspend fun clearEventCacheStorage(): Result<Unit>
239+
235240
/**
236241
* Share a location message in the room.
237242
*

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClientFactory.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ class RustMatrixClientFactory @Inject constructor(
109109
.addRootCertificates(userCertificatesProvider.provides())
110110
.autoEnableBackups(true)
111111
.autoEnableCrossSigning(true)
112-
// TODO Add a feature flag to enable persistent storage
113-
// See https://github.com/matrix-org/matrix-rust-sdk/pull/4396
114-
.useEventCachePersistentStorage(false)
112+
.useEventCachePersistentStorage(featureFlagService.isFeatureEnabled(FeatureFlags.EventCache))
115113
.roomKeyRecipientStrategy(
116114
strategy = if (featureFlagService.isFeatureEnabled(FeatureFlags.OnlySignedDeviceIsolationMode)) {
117115
CollectStrategy.IdentityBasedStrategy

libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RustMatrixRoom.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,12 @@ class RustMatrixRoom(
569569
}
570570
}
571571

572+
override suspend fun clearEventCacheStorage(): Result<Unit> = withContext(roomDispatcher) {
573+
runCatching {
574+
innerRoom.clearEventCacheStorage()
575+
}
576+
}
577+
572578
override suspend fun kickUser(userId: UserId, reason: String?): Result<Unit> = withContext(roomDispatcher) {
573579
runCatching {
574580
innerRoom.kickUser(userId.value, reason)

0 commit comments

Comments
 (0)