Commit Graph

15371 Commits

Author SHA1 Message Date
Ivan Enderlin
25abaefcb1 doc(sdk): Fix document in thread cache. 2026-05-29 14:36:02 +02:00
Ivan Enderlin
835ef77367 refactor(sdk): Introduce PinnedEventsCacheUpdateSender.
This patch introduces the new type `PinnedEventsCacheUpdateSender` _à
la_ `ThreadEventCacheUpdateSender` or `RoomEventCacheUpdateSender`. It
abstracts the channels to send updates about. Yes, for the moment, it
has a single channel, but it's better to provide the same abstractions
for all caches.
2026-05-29 14:36:02 +02:00
Ivan Enderlin
f87363a0a6 doc(sdk): Fix an intra-link. 2026-05-29 14:36:01 +02:00
Ivan Enderlin
fbbffda11f refactor(sdk): Rename PinnedEventsCacheStateLock to LockedPinnedEventsCacheState.
This patch renames `PinnedEventsCacheStateLock` to
`LockedPinnedEventsCacheState` to match other namings in
`RoomEventCache` and `ThreadEventCache` for the sake of consistency.
2026-05-29 14:36:01 +02:00
Ivan Enderlin
00e610cdd2 chore(sdk): PinnedEventsCache::new takes a WeakRoom instead of a Room.
This patch changes `PinnedEventsCache::new` to receive a `WeakRoom`
instead of a `Room`. It then returns a `Result<Self>`, with `Err` if the
`WeakRoom` doesn't point to the `Room` anymore. Thus, this patch changes
`get_or_init` by `get_or_try_init`, but this one is unstable. So this
patch switches from `OnceLock` to `OnceCell`, which provides a stable
one. Why this change? Because in a later refactoring, providing a `Room`
is a bit annoying: all we will have is a `WeakRoom`. We could do this
work of upgrading the `WeakRoom` to a `Room`, but it seems akward as all
caches are holding a `WeakRoom` if room is necessary.
2026-05-29 14:36:01 +02:00
Ivan Enderlin
3077d51ec8 refactor(sdk): Rename PinnedEventCache to PinnedEventsCache.
This patch renames `PinnedEventCache` to `PinnedEventsCache` (and same
for all types having `PinnedEventCache` as a prefix).

Why? Because it's a cache about _pinned-events_, not a single
_pinned-event_ :-).
2026-05-29 14:36:01 +02:00
Ivan Enderlin
48c1629791 doc(sdk): Remove a useless TODO. 2026-05-29 14:36:00 +02:00
Ivan Enderlin
f9df888cf3 chore(sdk): Implement Debug for PinnedEventCache. 2026-05-29 14:36:00 +02:00
Ivan Enderlin
d7f35742d4 test(sdj): Fix test_redact_touches_threads if async runtime is slow. 2026-05-29 14:36:00 +02:00
Ivan Enderlin
4d58a3c0db chore(sdk,ui): Fix typos. 2026-05-29 14:36:00 +02:00
Ivan Enderlin
8657a7788b test(sdk): Disable test_latest_thread_event_is_redecrypted_and_updated for now.
This test is not working because of R2D2 not updating threads for now.
This is normal. This is going to be refactored in a later PR.
2026-05-29 14:35:59 +02:00
Ivan Enderlin
e04f673ee7 chore(sdk): Make Clippy happy :-). 2026-05-29 14:35:59 +02:00
Ivan Enderlin
4fe1128385 fix(sdk): Restore the handling of bunlded_latest_thread_event in RoomEventCache. 2026-05-29 14:35:59 +02:00
Ivan Enderlin
58b0c5c893 test(sdk): Update to match the edit and redaction behaviours. 2026-05-29 14:35:59 +02:00
Ivan Enderlin
c5aad98768 feat(sdk): ThreadSummary uses the LatestEvent filtering API.
This patch updates the `compute_thread_summary` method on the thread
cache to use the `matrix_sdk::latest_events` API. It bends it, also
a crime. We don't use it at its full potential, but at least it fixes
several bugs and makes it more aligned with the room latest events: it
skips `m.room.redaction` (new), the majority of the state events (new),
mostly correctly handle edits (new) etc.

This patch also allows the system to erase the `ThreadSummary` if none
can be computed.
2026-05-29 14:35:58 +02:00
Ivan Enderlin
b352284e1a fix(ui): Updates from RoomEventCache are not forwarded to a Thread Timeline.
Previously, because a `ThreadEventCache` didn't receive all its events,
a `Timeline` with a `Thread` focus had to be updated via two sources:
updates from `RoomEventCache` and from `ThreadEventCache`. Now that this
problem is solved, i.e. a `ThreadEventCache` contains all its events,
a `Timeline` with a `Thread` focus doesn't have to be updated by two
sources. This is what this patch does.
2026-05-29 14:35:58 +02:00
Ivan Enderlin
4dc1a626ac feat(sdk): Annotations and redactions events are stored in their associated threads.
This patch stores all events with a relation to an in-thread event,
plus the `m.room.redaction` events targeting in-thread events, in their
respective thread cache.

This patch also introduces a new `extract_redaction_target` helper, that
is used in the `maybe_apply_new_redaction` methods of the room and the
thread cache.

The aggregator for the threads is updated to aggregate the
`m.room.redaction` event, and annotation relation type. A refactoring
is done to use a `match` over `RelationType`, instead of using multiple
`extract_*` helper, which clarifies the code I believe. A limitation has
been found and a `TODO` has been added to keep the commits “small”.
2026-05-29 14:35:58 +02:00
Ivan Enderlin
ef76aafdda test(sdk): Update tests to the new API. 2026-05-29 14:35:58 +02:00
Ivan Enderlin
dad3a7fb7a chore(sdk): Clean up the reset/clear API. 2026-05-29 14:35:57 +02:00
Ivan Enderlin
c855713638 refactor(ui): TimelineFocusKind holds the appropriate event cache.
This patch updates `TimelineFocusKind` to hold its own event cache type
for each kind of timeline. The idea is to stop fetching each cache for
every action and makes some path infallible. The performance are also
perceivably faster according to a real test by Jorge on Android.
2026-05-29 14:35:57 +02:00
Ivan Enderlin
8137fd316e chore(sdk): Remove a call to clone(). 2026-05-29 14:35:57 +02:00
Ivan Enderlin
7e39a080b6 feat(sdk): Implement std::fmt::Debug for RoomPagination and ThreadPagination. 2026-05-29 14:35:57 +02:00
Ivan Enderlin
387f0ece12 feat(sdk): Add EventCache::thread.
This patch adds `EventCache::thread`, sibling of `EventCache::room`.
Finally!
2026-05-29 14:35:56 +02:00
Ivan Enderlin
b9e72f5076 refactor(sdk): Rename EventCache::for_room to room and make it public. 2026-05-29 14:35:56 +02:00
Ivan Enderlin
d8f238e204 chore(sdk): Clean up imports. 2026-05-29 14:35:56 +02:00
Ivan Enderlin
6a6ef7a317 chore(sdk): Remove useless arguments in RoomEventCacheStateLockWriteGuard::post_process_new_events.
This patch cleans up `post_process_new_events` arguments that were
specific to thread or thread summary. I am aware that R2D2 had special
treatement here, and it's going to be re-introduced later.
2026-05-29 14:35:56 +02:00
Ivan Enderlin
fa0d438930 chore(sdk): Remove RoomEventCache::find_event_in_thread.
This patch removes `RoomEventCache::find_event_in_thread` as we now have
`ThreadEventCache::find_event`.
2026-05-29 14:35:56 +02:00
Ivan Enderlin
5a37930f1d chore(sdk): Remove RoomEventCacheState::threads.
This patch removes `RoomEventCacheState::threads` along with
`get_or_reload_patch` and `update_threads`.
2026-05-29 14:35:55 +02:00
Ivan Enderlin
bcb9e4471a chore(sdk): Split maybe_apply_new_redaction between RoomEventCache and ThreadEventCache.
This patch handles `m.room.redaction` for thread caches.

This is a naive approach for now to have small commits.
2026-05-29 14:35:55 +02:00
Ivan Enderlin
f153d85dd0 refactor(sdk): Move thread summary computation from RoomEventCache to ThreadEventCache.
This patch updates the `ThreadSummary` flow. `Caches` ask each thread to
compute its `ThreadSummary` and ask the room to update/store it.

The edit events targeting in-thread events are now stored in the thread
cache! This is new as it was only stored in the room cache previously.
This unlocks the possibility to correctly compute the latest event for a
thread with the `matrix_sdk::latest_events` API in the future.
2026-05-29 14:35:55 +02:00
Ivan Enderlin
ee3f1d785e chore(sdk): Use persistence::find_event in thread::state. 2026-05-29 14:35:55 +02:00
Ivan Enderlin
978b1b3aca refactor(sdk): Move the bundled_latest_thread_event handling from room's post process to thread's post process.
The room is post-processing thread events. This patch moves the
handling of `bunlded_latest_thread_event` from `RoomEventCache` to
`ThreadEventCache`.
2026-05-29 14:35:54 +02:00
Ivan Enderlin
c7d08f72ae refactor(sdk): Move find_event_relations and find_event_with_relations to persistence.
This patch moves the `find_event_relations` and
`find_event_with_relations` implementations in `persistence` with the
idea to share it with the thread caches.
2026-05-29 14:35:54 +02:00
Ivan Enderlin
f4c6d75788 refactor(sdk): Move find_event into persistence.
This patch moves the `find_event` implementation in `persistence` with
the idea to share it with the thread caches.
2026-05-29 14:35:54 +02:00
Ivan Enderlin
8a0ad649ca chore(sdk): Remove RoomEventCache::subscribe_to_thread.
This patch removes `RoomEventCache::subscribe_to_thread` as it is now
available on `ThreadEventCache::subscribe`.
2026-05-29 14:35:54 +02:00
Ivan Enderlin
91b9361a6f chore(sdk): Remove RoomEventCache::thread_pagination.
This patch removes `RoomEventCache::thread_pagination` as it is now
available on `ThreadEventCache::pagination`.
2026-05-29 14:35:53 +02:00
Ivan Enderlin
cea2dce65a refactor(sdk): Move threads from RoomEventCache to Caches.
This patch starts flattening caches by starting the extract thread
caches from the room cache.

This patch comments some methods or adds a `todo!()` to make the code
compile. It's the price for smaller commits.

The thread cache gains new methods like `handle_joined_room_update` or
`handle_joined_left_update`. It mimics the flow in the room cache.

A new `caches::aggregator` module is created to introduce “pipelines”:
a `Timeline` is created for each cache. It lives in front of the room
cache, and basically reverses the “post process” flow to a “pre process”
flow. More commits will improve it.

`ResetCaches` is now also responsible to clear the threads in addition
to the room (previously, the room cache was responsible of that).
2026-05-29 14:35:53 +02:00
Ivan Enderlin
713612ad85 feat(sdk): Implement OwnedThreadEventCacheStateLockWriteGuard.
This patch implements the exclusive owned lock guard for the thread
cache state.
2026-05-29 14:35:53 +02:00
Ivan Enderlin
48ed1e595e chore(sdk): Move methods from ThreadEventCacheStateLockWriteGuard to ThreadEventCacheState directly.
This method moves a couple of methods to `ThreadEventCacheState` so they
can be shared with other types in the next patches.
2026-05-29 14:35:53 +02:00
Ivan Enderlin
f0f65d4e56 feat(sdk): Implement StateLock::write_owned.
This patch implements `StateLock::write_owned` along with the
`OwnedStateLockWriteGuard`. This is going to be useful to acquire an
exclusive owned lock when we will need to reset all the caches.
2026-05-29 14:35:52 +02:00
Ivan Enderlin
4737ed406c chore(sdk): Improve an inline comment. 2026-05-29 14:35:52 +02:00
Ivan Enderlin
6730db9ff3 feat(sdk): Add LinkedChunk::first_chunk.
This patch adds `LinkedChunk::first_chunk`, and exposes it to
`EventLinkedChunk` to replace the use of 2 iterators in `RoomPagination`
and `ThreadPagination`, and to remove 2 `unwrap`s.
2026-05-29 14:35:52 +02:00
Ivan Enderlin
d6f599d3d4 chore(sdk): Remove the TODO from the documentation. 2026-05-29 14:35:52 +02:00
Ivan Enderlin
4e32455b47 test(sdk): Add test_reload_when_dirty for thread. 2026-05-29 14:35:51 +02:00
Ivan Enderlin
15a8fe5a32 fix(sdk): Reload all the “inner states” of a RoomEventCache at once.
`RoomEventCache` holds the states for the room cache, the thread caches,
and the pinned-events cache. When the cross-process lock is dirty, it
has to reload all these caches.

Ideally, we must move all the states in a single struct, behind the
cross-process lock, because right now, when the lock is dirty, only a
single room is reloaded, not all the rooms. This is a temporary fix.
2026-05-29 14:35:51 +02:00
Ivan Enderlin
45616fb899 test(sdk): Add test_load_from_storage_resilient_to_failure for thread. 2026-05-29 14:35:51 +02:00
Ivan Enderlin
e1d7cec7b5 test(sdk): Add test_load_from_storage for thread. 2026-05-29 14:35:51 +02:00
Ivan Enderlin
a03701cec5 feat(sdk): Emit a RoomEventCacheGenericUpdate when the ThreadEventCache is built.
This patch updates `ThreadEventCache::new` to emit a
`RoomEventCacheGenericUpdate` when it's built, similarly to
`RoomEventCache`. This is important for external API, like Latest Event.
2026-05-29 14:35:50 +02:00
Ivan Enderlin
f6f6b226b2 test(sdk): Add test_clear for thread. 2026-05-29 14:35:50 +02:00
Ivan Enderlin
1693e0f30d feat(sdk): ThreadEventCacheUpdateSender can send RoomEventCacheGenericUpdate.
This patch updates `ThreadEventCacheUpdateSender` to send
`RoomEventCacheGenericUpdate`. This is useful for `ThreadPagination`.
2026-05-29 14:35:50 +02:00