-
Notifications
You must be signed in to change notification settings - Fork 260
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
refactor(ui): Create a mapping between remote events to timeline items #4377
refactor(ui): Create a mapping between remote events to timeline items #4377
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4377 +/- ##
==========================================
+ Coverage 85.15% 85.21% +0.05%
==========================================
Files 280 281 +1
Lines 30831 30971 +140
==========================================
+ Hits 26254 26391 +137
- Misses 4577 4580 +3 ☔ View full report in Codecov by Sentry. |
db20d84
to
4c534b6
Compare
This is the foundation for the mapping between remote events and timeline items.
…anipulated. This patch maintains the `timeline_item_index` when a new remote events is added or removed.
…inserted or removed. This patch maintains the `timeline_item_index` when timeline items are inserted or removed.
b7c83d3
to
0376867
Compare
This patch moves `AllRemoteEvents` inside `observable_items` so that more methods can be made private, which reduces the risk of misuses of this API. In particular, the following methods are now strictly private: - `clear` - `push_front` - `push_back` - `remove` - `timeline_item_has_been_inserted_at` - `timeline_item_has_been_removed_at` In fact, now, all `&mut self` method (except `get_by_event_id_mut`) are now strictly private!
This patch renames `ObservableItems(Transaction)::set` to `replace`, it conveys the semantics a bit better for new comers.
…ry`. This patch creates `ObservableItemsEntries` and particularly `ObservableItemsEntry` that wraps the equivalent `ObservableVectorEntries` and `ObservableVectorEntry` with the noticeable difference that `ObservableItemsEntry` does **not** expose the `remove` method. It only exposes `replace` (which is a renaming of `set`).
This patch creates `ObservableItemsTransactionEntry` that mimics `ObservableVectorTransactionEntry`. The differences are `set` is renamed `replace`, and `remove` is unsafe (because I failed to update `AllRemoteEvents` in this method due to the borrow checker).
This patch adds test suite for `AllRemoteEvents`.
0059ab7
to
5fc48cc
Compare
I think there is a problem when replacing a timeline item. I need to investigate that. Moving back the PR as a draft. |
I think the current PR was actually alright. When editing a timeline item, its internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all of this makes sense, a bit challenging to review since some aspects of my review were already addressed in subsequent comments.
I mostly left a bunch of nits here and there. The unsafe
function makes me uneasy so would be good to rethink if we could express this a bit differently.
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-ui/src/timeline/controller/observable_items.rs
Outdated
Show resolved
Hide resolved
09a7280
to
0cc8226
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good.
0cc8226
to
bd648cd
Compare
A messenger trying to find its path in an unknown land
Don't be fooled by the number of new lines in this PR, patches are small and relatively easy to read. Most of the new lines are documentation or tests (around 1300).
The idea of this PR is to create a mapping between events to timeline items. More precisely, a mapping between event indexes and timeline item indexes. Why is this needed? We want
Timeline
to receive its updates viaVectorDiff
. ThoseVectorDiff
are generated by theEventCache
(vialinked_chunk::AsVector
). The indexes from theseVectorDiff
—likeVectorDiff::Insert { index, .. }
orVectorDiff::Remove { index }
— are event index. TheTimeline
manipulates a collection of timeline items, where each item has an event ID, but no event index.Fortunately for us, a recent patch has clarified an internal data type, now known as
AllRemoteEvents
(see #4370). We can re-use this type to maintain an index between the events and the timeline items.This PR must be reviewed patch-by-patch:
EventMeta::timeline_item_index
field, and maintains it. That's it, everything works at this step!ObservableItems
which is a new type that replaces/wrapsObservableVector<Arc<TimelineItem>>
: the idea is to provide a small API we control!AllRemoteEvents
is moved insideObservableItems
, so that operations on the items and the events happen “atomically”, which removes many possible errors of misuses.EventCache
storage #3280RoomEventCache
'sVectorDiff
toTimeline
#3512 but these patches have taken a very different approach with new types likeAllRemoteEvents
andObservableItems
types.