sdk-ui: use PinnedEventsLoader::update_if_needed when new timeline events are received. Using PinnedEventsLoader::load_events here was a mistake.

This commit is contained in:
Jorge Martín
2024-08-02 15:16:02 +02:00
committed by Jorge Martin Espinosa
parent 4de1375a76
commit 2bd4db8a23
3 changed files with 22 additions and 5 deletions

View File

@@ -22,7 +22,7 @@ use matrix_sdk::{
};
use ruma::{events::AnySyncTimelineEvent, RoomVersionId};
use tokio::sync::broadcast::error::RecvError;
use tracing::{info, info_span, trace, warn, Instrument, Span};
use tracing::{error, info, info_span, trace, warn, Instrument, Span};
#[cfg(feature = "e2e-encryption")]
use super::to_device::{handle_forwarded_room_key_event, handle_room_key_event};
@@ -269,8 +269,11 @@ impl TimelineBuilder {
// events, update the pinned events cache with them, reload the list of pinned event ids and reload
// the list of pinned events with this info.
if let TimelineFocus::PinnedEvents { .. } = &*focus.clone() {
if let Ok(events) = inner.pinned_events_load_events(&pinned_event_cache).await {
inner.replace_with_initial_remote_events(events, RemoteEventOrigin::Sync).await;
if let Some(ret) = inner.pinned_events_update(events, &pinned_event_cache).await {
match ret {
Ok(events) => inner.replace_with_initial_remote_events(events, RemoteEventOrigin::Sync).await,
Err(err) => error!("Couldn't update pinned events with incoming timeline events: {err}"),
}
}
} else {
inner.add_events_at(

View File

@@ -354,6 +354,20 @@ impl<P: RoomDataProvider> TimelineInner<P> {
}
}
pub(crate) async fn pinned_events_update(
&self,
events: Vec<SyncTimelineEvent>,
pinned_event_cache: &PinnedEventCache,
) -> Option<Result<Vec<SyncTimelineEvent>, PinnedEventsLoaderError>> {
let focus_guard = self.focus.read().await;
if let TimelineFocusData::PinnedEvents { loader } = &*focus_guard {
loader.update_if_needed(events, pinned_event_cache).await
} else {
Some(Err(PinnedEventsLoaderError::TimelineFocusNotPinnedEvents))
}
}
/// Run a backward pagination (in focused mode) and append the results to
/// the timeline.
///

View File

@@ -116,7 +116,7 @@ impl PinnedEventsLoader {
&self,
events: Vec<impl Into<SyncTimelineEvent>>,
cache: &PinnedEventCache,
) -> Option<Vec<SyncTimelineEvent>> {
) -> Option<Result<Vec<SyncTimelineEvent>, PinnedEventsLoaderError>> {
let mut to_update = Vec::new();
for ev in events {
let ev = ev.into();
@@ -129,7 +129,7 @@ impl PinnedEventsLoader {
if !to_update.is_empty() {
cache.set_bulk(&to_update).await;
self.load_events(cache).await.ok()
Some(self.load_events(cache).await)
} else {
None
}