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.
This patch renames `PinnedEventsCacheStateLock` to
`LockedPinnedEventsCacheState` to match other namings in
`RoomEventCache` and `ThreadEventCache` for the sake of consistency.
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.
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_ :-).
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.
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.
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”.
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.
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.
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.
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.
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).
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.
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.
`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.
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.