This patch updates R2D2 to uses `Caches` via
`EventCache::inner::all_caches_for_room` to get a reference to all the
caches. It updates the way the event-focused cache was updated. No more
ABBA lock problem here. The code is simplified.
This patch removes the `room` argument of
`EventFocusedCache(Inner)::start_from`. First off, this is not required
as the struct already has the `WeakRoom`. Second, this is dangerous as
the two rooms might differ, or different rooms might be used between
called. This can be really inconsistent.
This patch removes the `room` argument and the code uses the `WeakRoom`
in the struct instead.
This patch moves `maybe_add_live_related_events` to `handle_timeline`.
`handle_timeline` is called by `handle_(joined|left)_room_update`, which
are themselves called by `Caches`.
This patch also removes other methods used by
`maybe_add_live_related_events` but are no longer useful since
we have the aggregator, namely `extract_relation_target` and
`extract_redaction_target`.
Finally, this patch removes the call to `maybe_add_live_related_events`
in `RoomEventCacheStateLockWriteGuard::post_process_new_events`, which
removes the need to acquire a write lock over the room' state here.
This patch adds `EventCache::pinned_events` to get the `PinnedEventsCache`.
This patch adds `Caches::pinned_events`. `ResetCaches` also
handle the pinned-events cache. To make it works, this patch adds
`PinnedEventsCache::state`, `PinnedEventsCache::update_sender` and
`PinnedEventsCacheStateLockWriteGuard::reset`. This one is new as the
feature wasn't implemented before!
This patch adds `PinnedEventsCacheInner::update_sender`, making
`PinnedEventsCacheState::update_sender` a clone of the former.
This is going to be useful in the next commit for handling pinned-events
in `ResetCaches`.
This patch introduces the `PinnedEventsCacheInner` type that is used
inside `PinnedEventsCache` to make it cheap to clone. It was already the
case before with all the fields beind `Arc<_>` but we are about to move
data in their correct place, and thus it will add more `Arc<_>`, which
is not good. Let's adopt the same patterns as the other caches too for
the sake of consistency.
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.