From c4132252d36b72f4a71e614451cc98f24853e3a4 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 20 Dec 2024 10:27:48 +0100 Subject: [PATCH] feat(ui): Enable `TimelineSettings::vectordiffs_as_inputs` if event cache storage is enabled. This patch automatically enables `TimelineSettings::vectordiffs_as_inputs` if and only if the event cache storage is enabled. --- crates/matrix-sdk-ui/src/timeline/builder.rs | 9 +++++++-- crates/matrix-sdk/src/event_cache/mod.rs | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/builder.rs b/crates/matrix-sdk-ui/src/timeline/builder.rs index ab850666e..2032ad5f4 100644 --- a/crates/matrix-sdk-ui/src/timeline/builder.rs +++ b/crates/matrix-sdk-ui/src/timeline/builder.rs @@ -162,12 +162,17 @@ impl TimelineBuilder { ) )] pub async fn build(self) -> Result { - let Self { room, settings, unable_to_decrypt_hook, focus, internal_id_prefix } = self; - let settings_vectordiffs_as_inputs = settings.vectordiffs_as_inputs; + let Self { room, mut settings, unable_to_decrypt_hook, focus, internal_id_prefix } = self; let client = room.client(); let event_cache = client.event_cache(); + // Enable `TimelineSettings::vectordiffs_as_inputs` if and only if the event + // cache storage is enabled. + settings.vectordiffs_as_inputs = event_cache.has_storage(); + + let settings_vectordiffs_as_inputs = settings.vectordiffs_as_inputs; + // Subscribe the event cache to sync responses, in case we hadn't done it yet. event_cache.subscribe()?; diff --git a/crates/matrix-sdk/src/event_cache/mod.rs b/crates/matrix-sdk/src/event_cache/mod.rs index 20a3e90c3..6f2885839 100644 --- a/crates/matrix-sdk/src/event_cache/mod.rs +++ b/crates/matrix-sdk/src/event_cache/mod.rs @@ -175,6 +175,11 @@ impl EventCache { Ok(()) } + /// Check whether the storage is enabled or not. + pub fn has_storage(&self) -> bool { + self.inner.has_storage() + } + /// Starts subscribing the [`EventCache`] to sync responses, if not done /// before. ///