Skip to content

feat(sdk): Introduce the new LatestEvents API, part 3: Computing from the Send Queue #5482

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 9 commits into
base: main
Choose a base branch
from

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Aug 4, 2025

This patch adds a new feature to LatestEvents: it now listens to the SendQueue!

Most of the addition are related to tests. I've tried to keep the commits are small and atomic as possible. We follow and update the code gradually.

LatestEventValuesForLocalEvents

A new type is introduced to manage a buffer of LatestEventValue for local events: LatestEventValuesForLocalEvents. A bit of explanations.

The system does only receive RoomSendQueueUpdates. It's not designed to iterate over local events in the send queue when a local event is changed (cancelled, or updated for example). That's why we keep our own buffer here. Imagine the system receives 4 RoomSendQueueUpdate:

  1. RoomSendQueueUpdate::NewLocalEvent: new local event,
  2. RoomSendQueueUpdate::NewLocalEvent: new local event,
  3. RoomSendQueueUpdate::ReplacedLocalEvent: replaced the first local event,
  4. RoomSendQueueUpdate::CancelledLocalEvent: cancelled the second local event.

NewLocalEvents will trigger the computation of new LatestEventValues, but CancelledLocalEvent for example doesn't hold any information to compute a new LatestEventValue, so we need to remember the previous values, until the local events are sent and removed from this buffer.

Another reason why we need a buffer is to handle wedged local event. Imagine the system receives 3 RoomSendQueueUpdate:

  1. RoomSendQueueUpdate::NewLocalEvent: new local event,
  2. RoomSendQueueUpdate::NewLocalEvent: new local event,
  3. RoomSendQueueUpdate::SendError: the first local event has failed to be sent.

Because a SendError is received (targeting the first NewLocalEvent), the send queue is stopped. However, the LatestEventValue targets the second NewLocalEvent. The system must consider that when a local event is wedged, all the following local events must also be marked as wedged. And vice versa, when the send queue is able to send an event again, all the following local events must be marked as unwedged.

This type isolates a couple of methods designed to manage these specific behaviours.


@Hywan Hywan force-pushed the feat-sdk-latest-events-take-3 branch 2 times, most recently from f3d6c35 to b66b454 Compare August 6, 2025 09:36
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 92.31398% with 94 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.62%. Comparing base (13c30f6) to head (63ae70c).
⚠️ Report is 10 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rates/matrix-sdk/src/latest_events/latest_event.rs 93.27% 26 Missing and 44 partials ⚠️
crates/matrix-sdk/src/latest_events/mod.rs 85.79% 23 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5482      +/-   ##
==========================================
+ Coverage   88.57%   88.62%   +0.04%     
==========================================
  Files         340      340              
  Lines       93743    94891    +1148     
  Branches    93743    94891    +1148     
==========================================
+ Hits        83036    84097    +1061     
- Misses       6575     6617      +42     
- Partials     4132     4177      +45     

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

Copy link

codspeed-hq bot commented Aug 6, 2025

CodSpeed Performance Report

Merging #5482 will not alter performance

Comparing Hywan:feat-sdk-latest-events-take-3 (63ae70c) with main (4f0415d)

Summary

✅ 31 untouched benchmarks

@Hywan Hywan force-pushed the feat-sdk-latest-events-take-3 branch 6 times, most recently from 8f06956 to a554133 Compare August 12, 2025 14:27
Hywan added 7 commits August 18, 2025 15:12
…dates_task`.

This patch removes the intermediate `rooms` variable in a new block. The
read-lock can be used immediately.
This patch updates `LatestEvents` to listen to the updates from the
`SendQueue`. The `listen_to_event_cache_and_send_queue_updates` function
contains the important change. A new `LatestEventQueueUpdate` enum is
added to represent either an update from the event cache, or from the
send queue.

So far, `compute_latest_events` does nothing in particular, apart from
panicking with a `todo!()` when a send queue update is met.
…vents`.

This patch renames the `update` methods to `update_with_event_cache`
in the `latest_events` module. It frees the road to introduce
`update_with_send_queue`.
…ent`.

This patch updates `compute_latest_events` to broadcast a
`RoomSendQueueUpdate` onto `LatestEvent`. It introduces the new
`update_with_send_queue` method.
This patch splits the `LatestEventValue` type into `LatestEventValue`
+ `LatestEventKind`. Basically, all variants in `LatestEventValue` are
moved inside the new `LatestEventKind` enum. `LatestEventValue` keeps
`None`, and see the new `Remote`, `LocalIsSending` and `LocalIsWedged`
variants.

This patch also extracts the message-like handling of `find_and_map`
(now renamed `find_and_map_timeline_event`) into its own function:
`find_and_map_any_message_like_event_content`. This is going to be
handful for the send queue part.
This patch implements `LatestEvent::update_with_send_queue`.
It introduces an intermediate type, for the sake of clarity,
`LatestEventValuesForLocalEvents`.

The difficulty here is to keep a buffer of `LatestEventValue`s requested
by the `SendQueue`. Why? Because we want the latest event value, but we
only receive `RoomSendQueueUpdate`s, we can't iterate over local events
in the `SendQueue` like we do for the `EventCache` to re-compute the
latest event if a local event has been cancelled or updated.

A particular care must also be applied when a local event is wedged:
this local event and all its followings must be marked as wedged too,
so that the `LatestEventValue` is `LocalIsWedged`. Same when the local
event is unwedged.
@Hywan Hywan force-pushed the feat-sdk-latest-events-take-3 branch from 8b7aef0 to 15843a0 Compare August 18, 2025 13:15
Hywan added 2 commits August 18, 2025 15:27
This patch introduces `LatestEventKind::Redacted` to handle the case
where an event is supposed to be a latest event but has been redacted.
@Hywan Hywan force-pushed the feat-sdk-latest-events-take-3 branch from 15843a0 to 63ae70c Compare August 18, 2025 13:28
@Hywan Hywan marked this pull request as ready for review August 18, 2025 13:28
@Hywan Hywan requested a review from a team as a code owner August 18, 2025 13:28
@Hywan Hywan requested review from bnjbvr and removed request for a team August 18, 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