Skip to content
Merged
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 bindings/matrix-sdk-ffi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ All notable changes to this project will be documented in this file.

### Changes

- `Timeline::latest_event_id` now uses its `ui::Timeline::latest_event_id` counterpart, instead of getting the latest event from the timeline and then its id.([#5864](https://github.com/matrix-org/matrix-rust-sdk/pull/5864))
- Build Android ARM64 bindings using better default RUSTFLAGS (the same used for iOS ARM64). This should improve performance. [(#5854)](https://github.com/matrix-org/matrix-rust-sdk/pull/5854)

## [0.14.0] - 2025-09-04
Expand Down
4 changes: 2 additions & 2 deletions bindings/matrix-sdk-ffi/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ impl Timeline {
Ok(())
}

/// Returns the [`EventId`] of the latest event in the timeline.
/// Returns the latest [`EventId`] in the timeline.
pub async fn latest_event_id(&self) -> Option<String> {
self.inner.latest_event().await.and_then(|event| event.event_id().map(ToString::to_string))
self.inner.latest_event_id().await.as_deref().map(ToString::to_string)
}

/// Queues an event in the room's send queue so it's processed for
Expand Down
1 change: 1 addition & 0 deletions crates/matrix-sdk-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.

### Bug Fixes

- `Timeline::latest_event_id` won't take threaded events into account on live/event focused timelines if `hide_threaded_events` is enabled. This fixes a bug in `Timeline::mark_as_read` that incorrectly tried to send a read receipt for threaded events that aren't really part of those timelines. ([#5864](https://github.com/matrix-org/matrix-rust-sdk/pull/5864/))
- Avoid replacing timeline items when the encryption info is unchanged.
([#5660](https://github.com/matrix-org/matrix-rust-sdk/pull/5660))
- Improvement performance of `RoomList` by introducing a new `RoomListItem` type
Expand Down
12 changes: 10 additions & 2 deletions crates/matrix-sdk-ui/src/timeline/controller/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ pub(in crate::timeline) struct EventMeta {
/// The ID of the event.
pub event_id: OwnedEventId,

/// If this event is part of a thread, this will contain its thread root
/// event id.
pub thread_root_id: Option<OwnedEventId>,

/// Whether the event is among the timeline items.
pub visible: bool,

Expand Down Expand Up @@ -580,7 +584,11 @@ pub(in crate::timeline) struct EventMeta {
}

impl EventMeta {
pub fn new(event_id: OwnedEventId, visible: bool) -> Self {
Self { event_id, visible, timeline_item_index: None }
pub fn new(
event_id: OwnedEventId,
visible: bool,
thread_root_id: Option<OwnedEventId>,
) -> Self {
Self { event_id, thread_root_id, visible, timeline_item_index: None }
}
}
27 changes: 26 additions & 1 deletion crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,32 @@ impl TimelineController {
/// it's folded into another timeline item.
pub(crate) async fn latest_event_id(&self) -> Option<OwnedEventId> {
let state = self.state.read().await;
state.items.all_remote_events().last().map(|event_meta| &event_meta.event_id).cloned()
let filter_out_thread_events = match self.focus() {
TimelineFocusKind::Thread { .. } => false,
TimelineFocusKind::Live { hide_threaded_events } => hide_threaded_events.to_owned(),
TimelineFocusKind::Event { paginator } => {
paginator.get().is_some_and(|paginator| paginator.hide_threaded_events())
}
_ => true,
};

// In some timelines, threaded events are added to the `AllRemoteEvents`
// collection since they need to be taken into account to calculate read
// receipts, but we don't want to actually take them into account for returning
// the latest event id since they're not visibly in the timeline
state
.items
.all_remote_events()
.iter()
.rev()
.filter_map(|item| {
if !filter_out_thread_events || item.thread_root_id.is_none() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain with an inline comment here why we want to filter out event with a thread root?

Some(item.event_id.clone())
} else {
None
}
})
.next()
}

#[instrument(skip(self), fields(room_id = ?self.room().room_id()))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,12 @@ mod observable_items_tests {
}

fn event_meta(event_id: &str) -> EventMeta {
EventMeta { event_id: event_id.parse().unwrap(), timeline_item_index: None, visible: false }
EventMeta {
event_id: event_id.parse().unwrap(),
thread_root_id: None,
timeline_item_index: None,
visible: false,
}
}

macro_rules! assert_event_id {
Expand Down Expand Up @@ -1923,6 +1928,7 @@ impl AllRemoteEvents {
}

/// Return a reference to the last remote event if it exists.
#[cfg(test)]
pub fn last(&self) -> Option<&EventMeta> {
self.0.back()
}
Expand Down Expand Up @@ -2054,7 +2060,12 @@ mod all_remote_events_tests {
use super::{AllRemoteEvents, EventMeta};

fn event_meta(event_id: &str, timeline_item_index: Option<usize>) -> EventMeta {
EventMeta { event_id: event_id.parse().unwrap(), timeline_item_index, visible: false }
EventMeta {
event_id: event_id.parse().unwrap(),
thread_root_id: None,
timeline_item_index,
visible: false,
}
}

macro_rules! assert_events {
Expand Down
100 changes: 52 additions & 48 deletions crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
MilliSecondsSinceUnixEpoch,
Option<OwnedTransactionId>,
Option<TimelineAction>,
Option<OwnedEventId>,
bool,
)> {
let state_key: Option<String> = raw.get_field("state_key").ok().flatten();
Expand Down Expand Up @@ -534,6 +535,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
origin_server_ts,
transaction_id,
Some(TimelineAction::failed_to_parse(event_type, deserialization_error)),
None,
true,
))
}
Expand All @@ -550,7 +552,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
// Remember the event before returning prematurely.
// See [`ObservableItems::all_remote_events`].
self.add_or_update_remote_event(
EventMeta::new(event_id, false),
EventMeta::new(event_id, false, None),
sender.as_deref(),
origin_server_ts,
position,
Expand Down Expand Up @@ -628,63 +630,65 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
_ => (event.kind.into_raw(), None),
};

let (event_id, sender, timestamp, txn_id, timeline_action, should_add) = match raw
.deserialize()
{
// Classical path: the event is valid, can be deserialized, everything is alright.
Ok(event) => {
let (in_reply_to, thread_root) = self.meta.process_event_relations(
&event,
&raw,
bundled_edit_encryption_info,
&self.items,
self.focus.is_thread(),
);

let should_add = self.should_add_event_item(
room_data_provider,
settings,
&event,
thread_root.as_deref(),
position,
);

(
event.event_id().to_owned(),
event.sender().to_owned(),
event.origin_server_ts(),
event.transaction_id().map(ToOwned::to_owned),
TimelineAction::from_event(
event,
let (event_id, sender, timestamp, txn_id, timeline_action, thread_root, should_add) =
match raw.deserialize() {
// Classical path: the event is valid, can be deserialized, everything is alright.
Ok(event) => {
let (in_reply_to, thread_root) = self.meta.process_event_relations(
&event,
&raw,
bundled_edit_encryption_info,
&self.items,
self.focus.is_thread(),
);

let should_add = self.should_add_event_item(
room_data_provider,
utd_info
.map(|utd_info| (utd_info, self.meta.unable_to_decrypt_hook.as_ref())),
in_reply_to,
settings,
&event,
thread_root.as_deref(),
position,
);

(
event.event_id().to_owned(),
event.sender().to_owned(),
event.origin_server_ts(),
event.transaction_id().map(ToOwned::to_owned),
TimelineAction::from_event(
event,
&raw,
room_data_provider,
utd_info.map(|utd_info| {
(utd_info, self.meta.unable_to_decrypt_hook.as_ref())
}),
in_reply_to,
thread_root.clone(),
thread_summary,
)
.await,
thread_root,
thread_summary,
should_add,
)
.await,
should_add,
)
}
}

// The event seems invalid…
Err(e) => {
if let Some(tuple) =
self.maybe_add_error_item(position, room_data_provider, &raw, e, settings).await
{
tuple
} else {
return false;
// The event seems invalid…
Err(e) => {
if let Some(tuple) = self
.maybe_add_error_item(position, room_data_provider, &raw, e, settings)
.await
{
tuple
} else {
return false;
}
}
}
};
};

// Remember the event.
// See [`ObservableItems::all_remote_events`].
self.add_or_update_remote_event(
EventMeta::new(event_id.clone(), should_add),
EventMeta::new(event_id.clone(), should_add, thread_root),
Some(&sender),
Some(timestamp),
position,
Expand Down
7 changes: 6 additions & 1 deletion crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Timeline {
Some(item.to_owned())
}

/// Get the latest of the timeline's event items.
/// Get the latest of the timeline's event items, both remote and local.
pub async fn latest_event(&self) -> Option<EventTimelineItem> {
if self.controller.is_live() {
self.controller.items().await.iter().rev().find_map(|item| {
Expand All @@ -268,6 +268,11 @@ impl Timeline {
}
}

/// Get the latest of the timeline's remote event ids.
pub async fn latest_event_id(&self) -> Option<OwnedEventId> {
self.controller.latest_event_id().await
}

/// Get the current timeline items, along with a stream of updates of
/// timeline items.
///
Expand Down
Loading
Loading