Skip to content

feat(sdk): Introduce the new LatestEvents API #5298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Jun 27, 2025

This patch is the first part of the new LatestEvents API. It contains
the “framework”, i.e. the structure, tasks, logic to make it work, but
no latest events are computed for the moment.

The Latest Events API provides a lazy, reactive and efficient way to
compute the latest event for a room or a thread.

The latest event represents the last displayable and relevant event
a room or a thread has been received. It is usually displayed in a
summary, e.g. below the room title in a room list.

The entry point is LatestEvents. It is preferable to get a reference
to it from Client::latest_events, which already plugs everything to
build it. LatestEvents is using the EventCache and the SendQueue
to respectively get known remote events (i.e. synced from the server),
or local events (i.e. ones being sent).

Laziness

LatestEvents is lazy, it means that, despites LatestEvents
is listening to all EventCache or SendQueue updates, it will
only do something if one is expected to get the latest event for a
particular room or a particular thread. Concretely, it means that
until LatestEvents::for_room is called for a particular room, no
latest event will ever be computed for that room (and similarly with
LatestEvents::for_thread).

If one is no longer interested to get the latest event for a
particular room or thread, the LatestEvents::forget_room and
LatestEvents::forget_thread methods must be used.

Reactive

LatestEvents is designed to be reactive. Once one has fetched a
LatestEvent, it is recommended to immediately subscribe to its updates
with LatestEvent::subscribe.


This patch moves the `JoinHandleExt` trait and the
`AbortOnDrop` type from `matrix_sdk::sliding_sync::utils` into
`matrix_sdk_common::executor`. This is going to be useful for other
modules.
@Hywan Hywan force-pushed the feat-sdk-latest-events-take-1 branch 2 times, most recently from 072be79 to 839042b Compare June 27, 2025 12:20
Copy link

codecov bot commented Jun 27, 2025

Codecov Report

Attention: Patch coverage is 90.92784% with 44 lines in your changes missing coverage. Please review.

Project coverage is 88.74%. Comparing base (e0ab16f) to head (4d8c194).
Report is 47 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/matrix-sdk/src/latest_events/mod.rs 91.46% 31 Missing and 7 partials ⚠️
...rates/matrix-sdk/src/latest_events/latest_event.rs 53.84% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5298      +/-   ##
==========================================
- Coverage   90.20%   88.74%   -1.47%     
==========================================
  Files         334      331       -3     
  Lines      105120    89144   -15976     
  Branches   105120    89144   -15976     
==========================================
- Hits        94827    79107   -15720     
+ Misses       6233     6226       -7     
+ Partials     4060     3811     -249     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan Hywan force-pushed the feat-sdk-latest-events-take-1 branch 2 times, most recently from e06fa67 to f35a5c9 Compare June 27, 2025 13:01
This patch is the first part of the new `LatestEvents` API. It contains
the “framework”, i.e. the structure, tasks, logic to make it work, but
no latest events are computed for the moment.

The Latest Events API provides a lazy, reactive and efficient way to
compute the latest event for a room or a thread.

The latest event represents the last displayable and relevant event
a room or a thread has been received. It is usually displayed in a
_summary_, e.g. below the room title in a room list.

The entry point is `LatestEvents`. It is preferable to get a reference
to it from `Client::latest_events`, which already plugs everything to
build it. `LatestEvents` is using the `EventCache` and the `SendQueue`
to respectively get known remote events (i.e. synced from the server),
or local events (i.e. ones being sent).

\## Laziness

`LatestEvents` is lazy, it means that, despites `LatestEvents`
is listening to all `EventCache` or `SendQueue` updates, it will
only do something if one is expected to get the latest event for a
particular room or a particular thread. Concretely, it means that
until `LatestEvents::for_room` is called for a particular room, no
latest event will ever be computed for that room (and similarly with
`LatestEvents::for_thread`).

If one is no longer interested to get the latest event for a
particular room or thread, the `LatestEvents::forget_room` and
`LatestEvents::forget_thread` methods must be used.

\## Reactive

`LatestEvents` is designed to be reactive. Once one has fetched a
`LatestEvent`, it is recommended to immediately subscribe to its updates
with `LatestEvent::subscribe`.
@Hywan Hywan force-pushed the feat-sdk-latest-events-take-1 branch from f35a5c9 to 4d8c194 Compare June 27, 2025 13:17
@Hywan Hywan marked this pull request as ready for review June 27, 2025 13:28
@Hywan Hywan requested a review from a team as a code owner June 27, 2025 13:28
@Hywan Hywan requested review from stefanceriu and removed request for a team June 27, 2025 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant