Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ WeeChat = "WeeChat"
[default.extend-words]
# all of these are valid words, but should never appear in this repo
bellow = "below"
stat = "state"
sing = "sign"
singed = "signed"
singing = "signing"
Expand Down
5 changes: 1 addition & 4 deletions benchmarks/benches/room_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ pub fn load_pinned_events_benchmark(c: &mut Criterion) {
.unwrap();

let timeline = TimelineBuilder::new(&room)
.with_focus(TimelineFocus::PinnedEvents {
max_events_to_load: 100,
max_concurrent_requests: 10,
})
.with_focus(TimelineFocus::PinnedEvents)
.build()
.await
.expect("Could not create timeline");
Expand Down
9 changes: 2 additions & 7 deletions bindings/matrix-sdk-ffi/src/timeline/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ pub enum TimelineFocus {
/// The thread root event ID to focus on.
root_event_id: String,
},
PinnedEvents {
max_events_to_load: u16,
max_concurrent_requests: u16,
},
PinnedEvents,
}

impl TryFrom<TimelineFocus> for matrix_sdk_ui::timeline::TimelineFocus {
Expand Down Expand Up @@ -160,9 +157,7 @@ impl TryFrom<TimelineFocus> for matrix_sdk_ui::timeline::TimelineFocus {

Ok(Self::Thread { root_event_id: parsed_root_event_id })
}
TimelineFocus::PinnedEvents { max_events_to_load, max_concurrent_requests } => {
Ok(Self::PinnedEvents { max_events_to_load, max_concurrent_requests })
}
TimelineFocus::PinnedEvents => Ok(Self::PinnedEvents),
}
}
}
Expand Down
24 changes: 20 additions & 4 deletions crates/matrix-sdk-common/src/linked_chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ pub use updates::*;
/// An identifier for a linked chunk; borrowed variant.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LinkedChunkId<'a> {
/// A room's unthreaded timeline.
Room(&'a RoomId),
/// A room's thread.
Thread(&'a RoomId, &'a EventId),
/// A room's list of pinned events.
PinnedEvents(&'a RoomId),
}

impl Display for LinkedChunkId<'_> {
Expand All @@ -124,6 +128,9 @@ impl Display for LinkedChunkId<'_> {
Self::Thread(room_id, thread_root) => {
write!(f, "{room_id}:thread:{thread_root}")
}
Self::PinnedEvents(room_id) => {
write!(f, "{room_id}:pinned")
}
}
}
}
Expand All @@ -133,6 +140,7 @@ impl LinkedChunkId<'_> {
match self {
LinkedChunkId::Room(room_id) => room_id.to_string(),
LinkedChunkId::Thread(room_id, event_id) => format!("t:{room_id}:{event_id}"),
LinkedChunkId::PinnedEvents(room_id) => format!("pinned:{room_id}"),
}
}

Expand All @@ -142,6 +150,9 @@ impl LinkedChunkId<'_> {
LinkedChunkId::Thread(room_id, event_id) => {
OwnedLinkedChunkId::Thread((*room_id).to_owned(), (*event_id).to_owned())
}
LinkedChunkId::PinnedEvents(room_id) => {
OwnedLinkedChunkId::PinnedEvents((*room_id).to_owned())
}
}
}
}
Expand All @@ -156,11 +167,11 @@ impl PartialEq<&OwnedLinkedChunkId> for LinkedChunkId<'_> {
fn eq(&self, other: &&OwnedLinkedChunkId) -> bool {
match (self, other) {
(LinkedChunkId::Room(a), OwnedLinkedChunkId::Room(b)) => *a == b,
(LinkedChunkId::PinnedEvents(a), OwnedLinkedChunkId::PinnedEvents(b)) => *a == b,
(LinkedChunkId::Thread(r, ev), OwnedLinkedChunkId::Thread(r2, ev2)) => {
r == r2 && ev == ev2
}
(LinkedChunkId::Room(..), OwnedLinkedChunkId::Thread(..))
| (LinkedChunkId::Thread(..), OwnedLinkedChunkId::Room(..)) => false,
_ => false,
}
}
}
Expand All @@ -176,6 +187,7 @@ impl PartialEq<LinkedChunkId<'_>> for OwnedLinkedChunkId {
pub enum OwnedLinkedChunkId {
Room(OwnedRoomId),
Thread(OwnedRoomId, OwnedEventId),
PinnedEvents(OwnedRoomId),
}

impl Display for OwnedLinkedChunkId {
Expand All @@ -191,13 +203,17 @@ impl OwnedLinkedChunkId {
OwnedLinkedChunkId::Thread(room_id, event_id) => {
LinkedChunkId::Thread(room_id.as_ref(), event_id.as_ref())
}
OwnedLinkedChunkId::PinnedEvents(room_id) => {
LinkedChunkId::PinnedEvents(room_id.as_ref())
}
}
}

pub fn room_id(&self) -> &RoomId {
match self {
OwnedLinkedChunkId::Room(room_id) => room_id,
OwnedLinkedChunkId::Thread(room_id, ..) => room_id,
OwnedLinkedChunkId::Room(room_id)
| OwnedLinkedChunkId::Thread(room_id, ..)
| OwnedLinkedChunkId::PinnedEvents(room_id, ..) => room_id,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ All notable changes to this project will be documented in this file.

- Don't consider rooms in the banned state to be non-left rooms. This bug was
introduced due to the introduction of the banned state for rooms, and the
non-left room filter did not take the new room stat into account.
non-left room filter did not take the new room state into account.
([#4448](https://github.com/matrix-org/matrix-rust-sdk/pull/4448))

- Fix `EventTimelineItem::latest_edit_json()` when it is populated by a live
Expand Down
11 changes: 9 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,15 @@ impl TimelineBuilder {

let has_events = controller.init_focus(&focus, &room_event_cache).await?;

let pinned_events_join_handle = if matches!(focus, TimelineFocus::PinnedEvents { .. }) {
Some(spawn(pinned_events_task(room.pinned_event_ids_stream(), controller.clone())))
let pinned_events_join_handle = if matches!(focus, TimelineFocus::PinnedEvents) {
let (_initial_events, pinned_events_recv) =
room_event_cache.subscribe_to_pinned_events().await?;

Some(spawn(pinned_events_task(
room_event_cache.clone(),
controller.clone(),
pinned_events_recv,
)))
} else {
None
};
Expand Down
55 changes: 12 additions & 43 deletions crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ use crate::{
MsgLikeContent, MsgLikeKind, Room, TimelineEventFilterFn, TimelineEventFocusThreadMode,
algorithms::rfind_event_by_item_id,
controller::decryption_retry_task::compute_redecryption_candidates,
date_dividers::DateDividerAdjuster,
event_item::TimelineItemHandle,
pinned_events_loader::{PinnedEventsLoader, PinnedEventsLoaderError},
date_dividers::DateDividerAdjuster, event_item::TimelineItemHandle,
},
unable_to_decrypt_hook::UtdHookManager,
};
Expand Down Expand Up @@ -121,9 +119,7 @@ pub(in crate::timeline) enum TimelineFocusKind<P: RoomDataProvider> {
root_event_id: OwnedEventId,
},

PinnedEvents {
loader: PinnedEventsLoader,
},
PinnedEvents,
}

#[derive(Debug)]
Expand Down Expand Up @@ -225,7 +221,7 @@ impl<P: RoomDataProvider> TimelineFocusKind<P> {
TimelineFocusKind::Event { paginator } => {
paginator.get().is_some_and(|paginator| paginator.hide_threaded_events())
}
TimelineFocusKind::Thread { .. } | TimelineFocusKind::PinnedEvents { .. } => false,
TimelineFocusKind::Thread { .. } | TimelineFocusKind::PinnedEvents => false,
}
}

Expand All @@ -241,7 +237,7 @@ impl<P: RoomDataProvider> TimelineFocusKind<P> {
TimelineFocusKind::Event { paginator, .. } => {
paginator.get().and_then(|paginator| paginator.thread_root())
}
TimelineFocusKind::Live { .. } | TimelineFocusKind::PinnedEvents { .. } => None,
TimelineFocusKind::Live { .. } | TimelineFocusKind::PinnedEvents => None,
TimelineFocusKind::Thread { root_event_id } => Some(root_event_id),
}
}
Expand Down Expand Up @@ -404,15 +400,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
TimelineFocusKind::Thread { root_event_id }
}

TimelineFocus::PinnedEvents { max_events_to_load, max_concurrent_requests } => {
TimelineFocusKind::PinnedEvents {
loader: PinnedEventsLoader::new(
Arc::new(room_data_provider.clone()),
max_events_to_load as usize,
max_concurrent_requests as usize,
),
}
}
TimelineFocus::PinnedEvents => TimelineFocusKind::PinnedEvents,
};

let focus = Arc::new(focus);
Expand Down Expand Up @@ -623,23 +611,14 @@ impl<P: RoomDataProvider> TimelineController<P> {
Ok(has_events)
}

TimelineFocus::PinnedEvents { .. } => {
let TimelineFocusKind::PinnedEvents { loader } = &*self.focus else {
// NOTE: this is sync'd with code in the ctor.
unreachable!();
};
TimelineFocus::PinnedEvents => {
let (initial_events, _update_receiver) =
room_event_cache.subscribe_to_pinned_events().await?;

let Some(loaded_events) =
loader.load_events().await.map_err(Error::PinnedEventsError)?
else {
// There wasn't any events.
return Ok(false);
};

let has_events = !loaded_events.is_empty();
let has_events = !initial_events.is_empty();

self.replace_with_initial_remote_events(
loaded_events,
initial_events,
RemoteEventOrigin::Pagination,
)
.await;
Expand Down Expand Up @@ -680,16 +659,6 @@ impl<P: RoomDataProvider> TimelineController<P> {
}
}

pub(crate) async fn reload_pinned_events(
&self,
) -> Result<Option<Vec<TimelineEvent>>, PinnedEventsLoaderError> {
if let TimelineFocusKind::PinnedEvents { loader } = &*self.focus {
loader.load_events().await
} else {
Err(PinnedEventsLoaderError::TimelineFocusNotPinnedEvents)
}
}

/// Run a lazy backwards pagination (in live mode).
///
/// It adjusts the `count` value of the `Skip` higher-order stream so that
Expand Down Expand Up @@ -723,7 +692,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
) -> Result<bool, PaginationError> {
let PaginationResult { events, hit_end_of_timeline } = match &*self.focus {
TimelineFocusKind::Live { .. }
| TimelineFocusKind::PinnedEvents { .. }
| TimelineFocusKind::PinnedEvents
| TimelineFocusKind::Thread { .. } => {
return Err(PaginationError::NotSupported);
}
Expand Down Expand Up @@ -756,7 +725,7 @@ impl<P: RoomDataProvider> TimelineController<P> {
) -> Result<bool, PaginationError> {
let PaginationResult { events, hit_end_of_timeline } = match &*self.focus {
TimelineFocusKind::Live { .. }
| TimelineFocusKind::PinnedEvents { .. }
| TimelineFocusKind::PinnedEvents
| TimelineFocusKind::Thread { .. } => return Err(PaginationError::NotSupported),

TimelineFocusKind::Event { paginator, .. } => paginator
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/timeline/controller/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<P: RoomDataProvider> TimelineState<P> {
TimelineFocusKind::Thread { root_event_id, .. } => {
thread_root.as_ref().is_some_and(|r| r == root_event_id)
}
TimelineFocusKind::Event { .. } | TimelineFocusKind::PinnedEvents { .. } => {
TimelineFocusKind::Event { .. } | TimelineFocusKind::PinnedEvents => {
// Don't add new items to these timelines; aggregations are added independently
// of the `should_add_new_items` value.
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
}

match &self.focus {
TimelineFocusKind::PinnedEvents { .. } => {
// Only add pinned events for the pinned events timeline.
room_data_provider.is_pinned_event(event.event_id())
TimelineFocusKind::PinnedEvents => {
// The pinned events timeline only receives updates for, well, pinned events.
true
}

TimelineFocusKind::Event { paginator } => {
Expand Down
6 changes: 1 addition & 5 deletions crates/matrix-sdk-ui/src/timeline/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use matrix_sdk::{
};
use thiserror::Error;

use crate::timeline::{TimelineEventItemId, pinned_events_loader::PinnedEventsLoaderError};
use crate::timeline::TimelineEventItemId;

/// Errors specific to the timeline.
#[derive(Error, Debug)]
Expand Down Expand Up @@ -60,10 +60,6 @@ pub enum Error {
#[error(transparent)]
PaginationError(#[from] PaginationError),

/// An error happened during pagination.
#[error(transparent)]
PinnedEventsError(#[from] PinnedEventsLoaderError),

/// An error happened while operating the room's send queue.
#[error(transparent)]
SendQueueError(#[from] RoomSendQueueError),
Expand Down
5 changes: 2 additions & 3 deletions crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub mod futures;
mod item;
mod latest_event;
mod pagination;
mod pinned_events_loader;
mod subscriber;
mod tasks;
#[cfg(test)]
Expand Down Expand Up @@ -146,7 +145,7 @@ pub enum TimelineFocus {
Thread { root_event_id: OwnedEventId },

/// Only show pinned events.
PinnedEvents { max_events_to_load: u16, max_concurrent_requests: u16 },
PinnedEvents,
}

/// Options for controlling the behaviour of [`TimelineFocus::Event`]
Expand Down Expand Up @@ -180,7 +179,7 @@ impl TimelineFocus {
TimelineFocus::Live { .. } => "live".to_owned(),
TimelineFocus::Event { target, .. } => format!("permalink:{target}"),
TimelineFocus::Thread { root_event_id, .. } => format!("thread:{root_event_id}"),
TimelineFocus::PinnedEvents { .. } => "pinned-events".to_owned(),
TimelineFocus::PinnedEvents => "pinned-events".to_owned(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/timeline/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl super::Timeline {
.event_cache
.paginate_thread_backwards(root_event_id.to_owned(), num_events)
.await?),
TimelineFocusKind::PinnedEvents { .. } => Err(Error::PaginationError(NotSupported)),
TimelineFocusKind::PinnedEvents => Err(Error::PaginationError(NotSupported)),
}
}

Expand Down
Loading
Loading