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.
This patch fixes an invalid behaviour in a thread: when an in-thread
event was redacted, it was removed from the thread. This is inconsistent
regarding in-room event redaction where a redacted event is updated to
its redacted form and the redaction event is added to the timeline. This
patch makes the behaviour consistent by updating the redacted event.
Basically, it replaces `remove_if_present` (deleted) by
`replace_event_if_present` (new).
This patch replaces the construction of an event by its equivalent in a
variable. The test uses `first_event` and `second_event`, but builds the
“`second_event`” manually for no reason, it's just confusing
This patch creates the `ThreadEventCacheUpdateSender` à la
`RoomEventCacheUpdateSender` to abstract the sender.
This patch uses `ThreadEventCacheUpdateSender` in
`ThreadEventCacheInner` (new) along with `ThreadEventCacheState`. The
use in the `ThreadEventCacheInner` type is necessary to be able to send
updates without reaching the state (which is behind an async faillible
lock). This is necessary for pagination, see next commit.
This patch replaces
`ThreadEventCacheStateLockWriteGuard::filter_duplicate_events` by
`deduplicator::filter_duplicate_events`. First off, this function is
shared between multiple event caches. Second, it deduplicates events
regarding in-memory and in-store state.
The calls to `ThreadEventCacheStateLockWriteGuard::remove_events` have
been updated to pass the duplicated in-store events.
This patch updates `ThreadEventCacheStateLockWriteGuard::remove_events`
to also remove events from the store (it was only removing events from
the in-memory LinkedChunk prior to this patch).
This patch moves the `load_linked_chunk_metadata` function from
`event_cache::caches::room::state` to `event_cache::persistence`. It's
going to be useful for `ThreadEventCache`.
This patch checks if the `EventCacheStoreLock` is dirty when
constructing `LockedThreadEventCacheState`. This patch is the first
step, but it involved a bit of refactoring since `new` is now fallible
and async. It propagates up to the public API which were already
fallible and async fortunately for us: no breaking change.
This patch changes `get_or_reload` to not clone the room ID, the store
etc. every time, but rather only when the `ThreadEventCache` must be
created.