From 9ade32fcd0ea860f90ec86ff216e12f06ab88e32 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 1 Jul 2025 11:34:43 +0200 Subject: [PATCH] refactor(timeline): remove generic from a few function signatures by using plain bools --- .../src/timeline/controller/metadata.rs | 26 ++++++++----------- .../src/timeline/controller/mod.rs | 5 +++- .../src/timeline/controller/state.rs | 3 ++- .../timeline/controller/state_transaction.rs | 6 +++-- .../matrix-sdk-ui/src/timeline/subscriber.rs | 6 ++--- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs b/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs index 8b267da21..781dd5aec 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs @@ -38,12 +38,10 @@ use super::{ }; use crate::{ timeline::{ - controller::TimelineFocusKind, event_item::{ extract_bundled_edit_event_json, extract_poll_edit_content, extract_room_msg_edit_content, }, - traits::RoomDataProvider, InReplyToDetails, TimelineEventItemId, }, unable_to_decrypt_hook::UtdHookManager, @@ -312,13 +310,13 @@ impl TimelineMetadata { /// Extract the content from a remote message-like event and process its /// relations. - pub(crate) fn process_event_relations( + pub(crate) fn process_event_relations( &mut self, event: &AnySyncTimelineEvent, raw_event: &Raw, bundled_edit_encryption_info: Option>, timeline_items: &Vector>, - timeline_focus: &TimelineFocusKind

, + is_thread_focus: bool, ) -> (Option, Option) { if let AnySyncTimelineEvent::MessageLike(ev) = event { if let Some(content) = ev.original_content() { @@ -332,7 +330,7 @@ impl TimelineMetadata { &content, remote_ctx, timeline_items, - timeline_focus, + is_thread_focus, ); } } @@ -344,19 +342,19 @@ impl TimelineMetadata { /// (like marking responses). /// /// Returns the in-reply-to details and the thread root event ID, if any. - pub(crate) fn process_content_relations( + pub(crate) fn process_content_relations( &mut self, content: &AnyMessageLikeEventContent, remote_ctx: Option>, timeline_items: &Vector>, - timeline_focus: &TimelineFocusKind

, + is_thread_focus: bool, ) -> (Option, Option) { match content { AnyMessageLikeEventContent::Sticker(content) => { let (in_reply_to, thread_root) = Self::extract_reply_and_thread_root( content.relates_to.clone().and_then(|rel| rel.try_into().ok()), timeline_items, - timeline_focus, + is_thread_focus, ); if let Some(event_id) = remote_ctx.map(|ctx| ctx.event_id) { @@ -372,7 +370,7 @@ impl TimelineMetadata { let (in_reply_to, thread_root) = Self::extract_reply_and_thread_root( c.relates_to.clone(), timeline_items, - timeline_focus, + is_thread_focus, ); // Record the bundled edit in the aggregations set, if any. @@ -410,7 +408,7 @@ impl TimelineMetadata { let (in_reply_to, thread_root) = Self::extract_reply_and_thread_root( msg.relates_to.clone().and_then(|rel| rel.try_into().ok()), timeline_items, - timeline_focus, + is_thread_focus, ); // Record the bundled edit in the aggregations set, if any. @@ -450,10 +448,10 @@ impl TimelineMetadata { /// Extracts the in-reply-to details and thread root from a relation, if /// available. - fn extract_reply_and_thread_root( + fn extract_reply_and_thread_root( relates_to: Option, timeline_items: &Vector>, - timeline_focus: &TimelineFocusKind

, + is_thread_focus: bool, ) -> (Option, Option) { let mut thread_root = None; @@ -464,9 +462,7 @@ impl TimelineMetadata { RelationWithoutReplacement::Thread(thread) => { thread_root = Some(thread.event_id); - if matches!(timeline_focus, TimelineFocusKind::Thread { .. }) - && thread.is_falling_back - { + if is_thread_focus && thread.is_falling_back { // In general, a threaded event is marked as a response to the previous message // in the thread, to maintain backwards compatibility with clients not // supporting threads. diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index e556aaa22..9b0dbfbd5 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -285,6 +285,7 @@ impl TimelineController { TimelineFocus::Live { hide_threaded_events } => { TimelineFocusKind::Live { hide_threaded_events } } + TimelineFocus::Event { target, num_context_events, hide_threaded_events } => { let paginator = Paginator::new(room_data_provider.clone()); TimelineFocusKind::Event { @@ -480,7 +481,9 @@ impl TimelineController { .subscriber_skip_count .compute_next_when_paginating_backwards(num_events.into()); - state.meta.subscriber_skip_count.update(count, &self.focus); + // This always happens on a live timeline. + let is_live_timeline = true; + state.meta.subscriber_skip_count.update(count, is_live_timeline); needs } diff --git a/crates/matrix-sdk-ui/src/timeline/controller/state.rs b/crates/matrix-sdk-ui/src/timeline/controller/state.rs index c55da5de3..e753b30d1 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/state.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/state.rs @@ -159,8 +159,9 @@ impl TimelineState

{ let mut date_divider_adjuster = DateDividerAdjuster::new(date_divider_mode); + let is_thread_focus = matches!(txn.focus, TimelineFocusKind::Thread { .. }); let (in_reply_to, thread_root) = - txn.meta.process_content_relations(&content, None, &txn.items, txn.focus); + txn.meta.process_content_relations(&content, None, &txn.items, is_thread_focus); // TODO merge with other should_add, one way or another? let should_add_new_items = match &txn.focus { diff --git a/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs b/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs index c007f902e..6bb1d02ea 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs @@ -625,7 +625,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> { &raw, bundled_edit_encryption_info, &self.items, - self.focus, + matches!(self.focus, TimelineFocusKind::Thread { .. }), ); let should_add = self.should_add_event_item( @@ -808,7 +808,9 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> { .meta .subscriber_skip_count .compute_next(previous_number_of_items, next_number_of_items); - self.meta.subscriber_skip_count.update(count, self.focus); + self.meta + .subscriber_skip_count + .update(count, matches!(self.focus, TimelineFocusKind::Live { .. })); } // Replace the pointer to the previous meta with the new one. diff --git a/crates/matrix-sdk-ui/src/timeline/subscriber.rs b/crates/matrix-sdk-ui/src/timeline/subscriber.rs index 7580df33f..d018de1c0 100644 --- a/crates/matrix-sdk-ui/src/timeline/subscriber.rs +++ b/crates/matrix-sdk-ui/src/timeline/subscriber.rs @@ -109,8 +109,6 @@ impl Stream for TimelineSubscriber { pub mod skip { use eyeball::{SharedObservable, Subscriber}; - use crate::timeline::{controller::TimelineFocusKind, traits::RoomDataProvider}; - const MAXIMUM_NUMBER_OF_INITIAL_ITEMS: usize = 20; /// `SkipCount` helps to manage the `count` value used by the [`Skip`] @@ -248,8 +246,8 @@ pub mod skip { /// Update the skip count if and only if the timeline has a live focus /// ([`TimelineFocusKind::Live`]). - pub fn update(&self, count: usize, focus: &TimelineFocusKind

) { - if matches!(focus, TimelineFocusKind::Live { .. }) { + pub fn update(&self, count: usize, is_live_focus: bool) { + if is_live_focus { self.count.set_if_not_eq(count); } }