Skip to content

Commit e15ddf6

Browse files
committed
pinned events(refactor): simplify handling of AddTimelineEvents
The timeline already listens to changes to the pinned events list (via a stream), so there's no need to fully reload all the pinned events every time we receive a new event that's pinned. Technically it may avoid one or a few lookups, but this is cheap and a subsequent commit/PR will merge the pinned event cache into the event cache.
1 parent 19b6495 commit e15ddf6

File tree

3 files changed

+4
-62
lines changed

3 files changed

+4
-62
lines changed

crates/matrix-sdk-ui/src/timeline/builder.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use matrix_sdk::{
2222
};
2323
use ruma::{events::AnySyncTimelineEvent, RoomVersionId};
2424
use tokio::sync::broadcast::error::RecvError;
25-
use tracing::{error, info, info_span, trace, warn, Instrument, Span};
25+
use tracing::{info, info_span, trace, warn, Instrument, Span};
2626

2727
#[cfg(feature = "e2e-encryption")]
2828
use super::to_device::{handle_forwarded_room_key_event, handle_room_key_event};
@@ -207,8 +207,6 @@ impl TimelineBuilder {
207207
info_span!(parent: Span::none(), "room_update_handler", room_id = ?room.room_id());
208208
span.follows_from(Span::current());
209209

210-
let focus = Arc::new(focus);
211-
212210
async move {
213211
trace!("Spawned the event subscriber task.");
214212

@@ -265,22 +263,9 @@ impl TimelineBuilder {
265263
RoomEventCacheUpdate::AddTimelineEvents { events, origin } => {
266264
trace!("Received new timeline events.");
267265

268-
// Special case for pinned events: when we receive new events what
269-
// we'll do is, instead of adding the events, update the pinned events
270-
// cache with them, reload the list of pinned event ids and reload the
271-
// list of pinned events with this info.
272-
273-
// TODO(bnjbvr): why is this done? the timeline already listens to
274-
// changes to the pinned events list, so we shouldn't have to trigger a
275-
// manual update here too.
276-
if let TimelineFocus::PinnedEvents { .. } = &*focus.clone() {
277-
if let Some(ret) = inner.update_pinned_events_if_needed(events, &pinned_event_cache).await {
278-
match ret {
279-
Ok(events) => inner.replace_with_initial_remote_events(events, RemoteEventOrigin::Sync).await,
280-
Err(err) => error!("Couldn't update pinned events with incoming timeline events: {err}"),
281-
}
282-
}
283-
} else {
266+
// Note: we deliberately choose to not handle
267+
// updates/reactions/redactions for pinned events.
268+
if !is_pinned_events {
284269
inner.add_events_at(
285270
events,
286271
TimelineEnd::Back,

crates/matrix-sdk-ui/src/timeline/inner/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,6 @@ impl<P: RoomDataProvider> TimelineInner<P> {
354354
}
355355
}
356356

357-
pub(crate) async fn update_pinned_events_if_needed(
358-
&self,
359-
events: Vec<SyncTimelineEvent>,
360-
pinned_event_cache: &PinnedEventCache,
361-
) -> Option<Result<Vec<SyncTimelineEvent>, PinnedEventsLoaderError>> {
362-
let focus_guard = self.focus.read().await;
363-
364-
if let TimelineFocusData::PinnedEvents { loader } = &*focus_guard {
365-
loader.update_if_needed(events, pinned_event_cache).await
366-
} else {
367-
Some(Err(PinnedEventsLoaderError::TimelineFocusNotPinnedEvents))
368-
}
369-
}
370-
371357
/// Run a backward pagination (in focused mode) and append the results to
372358
/// the timeline.
373359
///

crates/matrix-sdk-ui/src/timeline/pinned_events_loader.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,6 @@ impl PinnedEventsLoader {
118118

119119
Ok(loaded_events)
120120
}
121-
122-
/// Updates the cache with the provided events if they're associated with a
123-
/// pinned event id, then reloads the list of pinned events if there
124-
/// were any changes.
125-
///
126-
/// Returns an `Option` with either a new list of events if any of them
127-
/// changed in this update or `None` if they didn't.
128-
pub async fn update_if_needed(
129-
&self,
130-
events: Vec<impl Into<SyncTimelineEvent>>,
131-
cache: &PinnedEventCache,
132-
) -> Option<Result<Vec<SyncTimelineEvent>, PinnedEventsLoaderError>> {
133-
let mut to_update = Vec::new();
134-
for ev in events {
135-
let ev = ev.into();
136-
if let Some(ev_id) = ev.event_id() {
137-
if self.room.is_pinned_event(&ev_id) {
138-
to_update.push(ev);
139-
}
140-
}
141-
}
142-
143-
if !to_update.is_empty() {
144-
cache.set_bulk(to_update).await;
145-
Some(self.load_events(cache).await)
146-
} else {
147-
None
148-
}
149-
}
150121
}
151122

152123
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]

0 commit comments

Comments
 (0)