Skip to content
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

Merged
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a71afd1
refactor(ui): Add `EventMeta::timeline_item_index`.
Hywan Dec 4, 2024
8c7c4c2
refactor(ui): Maintain `timeline_item_index` when remote events are m…
Hywan Dec 4, 2024
7e5bc05
refactor(ui): Maintain `timeline_item_index` when timeline items are …
Hywan Dec 4, 2024
3e9026a
refactor(ui): Create `ObservableItems(Transaction)`.
Hywan Dec 4, 2024
88cd5b4
refactor(ui): Move `AllRemoteEvents` inside `observable_items`.
Hywan Dec 4, 2024
cefd116
doc(ui): Add more documentation.
Hywan Dec 4, 2024
6175298
refactor(ui): Rename `ObservableItems::set` to `replace`.
Hywan Dec 4, 2024
6458404
refactor(ui): Create `ObservableItemsEntries` and `ObservableItemsEnt…
Hywan Dec 4, 2024
1ced997
doc(ui): Add more documentation for `ObservableItemsTransaction`.
Hywan Dec 4, 2024
c997074
refactor(ui): Create `ObservableItemsTransactionEntry`.
Hywan Dec 4, 2024
482e390
doc(ui): Add more documentation for `AllRemoteEvents`.
Hywan Dec 4, 2024
581383e
chore: Make Clippy happy.
Hywan Dec 4, 2024
7292536
test(ui): Write test suite for `AllRemoteEvents`.
Hywan Dec 4, 2024
5fc48cc
test(ui): Write test suite for `ObservableItems`.
Hywan Dec 4, 2024
c41776a
refactor(ui): `ObservableItemsTransactionEntry::remove` is no longer …
Hywan Dec 9, 2024
c9a215e
doc(ui): Fix typos.
Hywan Dec 9, 2024
8b02da3
doc(ui): Document `ObservableItems::items` more and `TimelineItemKind`.
Hywan Dec 9, 2024
0f58464
doc(ui): Rephrase the documentation of `ObservableItems::all_remote_e…
Hywan Dec 9, 2024
bfd7b03
refactor(ui): Replace a panic by a sensible value + `error!`.
Hywan Dec 9, 2024
4ed9e73
refactor(ui): Rename `ObservableItems::clone` to `clone_items`.
Hywan Dec 9, 2024
650ac70
doc(ui): Explain why `Deref` is fine, but `DerefMut` is not.
Hywan Dec 9, 2024
a94556a
doc(ui): Explain why `ObservableItemsEntries` does not implement `Ite…
Hywan Dec 9, 2024
5004670
doc(ui): Unfold a `Self` in the doc.
Hywan Dec 9, 2024
04f9403
doc(ui): Fix a typo.
Hywan Dec 9, 2024
bd648cd
doc(ui): Fix typos.
Hywan Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion crates/matrix-sdk-ui/src/timeline/controller/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,11 @@ pub(crate) struct FullEventMeta<'a> {

impl FullEventMeta<'_> {
fn base_meta(&self) -> EventMeta {
EventMeta { event_id: self.event_id.to_owned(), visible: self.visible }
EventMeta {
event_id: self.event_id.to_owned(),
visible: self.visible,
timeline_item_index: None,
}
}
}

Expand All @@ -1208,6 +1212,70 @@ impl FullEventMeta<'_> {
pub(crate) struct EventMeta {
/// The ID of the event.
pub event_id: OwnedEventId,

/// Whether the event is among the timeline items.
pub visible: bool,

/// Foundation for the mapping between remote events to timeline items.
///
/// Let's explain it. The events represent the first set and are stored in
/// [`TimelineMetadata::all_remote_events`], and the timeline
/// items represent the second set and are stored in
/// [`TimelineState::items`].
///
/// Each event is mapped to at most one timeline item:
///
/// - `None` if the event isn't rendered in the timeline (e.g. some state
/// events, or malformed events) or is rendered as a timeline item that
/// attaches to or groups with another item, like reactions,
/// - `Some(_)` if the event is rendered in the timeline.
///
/// This is neither a surjection nor an injection. Every timeline item may
/// not be attached to an event, for example with a virtual timeline item.
/// We can formulate other rules:
///
/// - a timeline item that doesn't _move_ and that is represented by an
/// event has a mapping to an event,
/// - a virtual timeline item has no mapping to an event.
///
/// Imagine the following remote events:
///
/// | index | remote events |
/// +-------+---------------+
/// | 0 | `$ev0` |
/// | 1 | `$ev1` |
/// | 2 | `$ev2` |
/// | 3 | `$ev3` |
/// | 4 | `$ev4` |
/// | 5 | `$ev5` |
///
/// Once rendered in a timeline, it for example produces:
///
/// | index | item | aside items |
Hywan marked this conversation as resolved.
Show resolved Hide resolved
/// +-------+-------------------+----------------------+
/// | 0 | content of `$ev0` | |
/// | 1 | content of `$ev2` | reaction with `$ev4` |
/// | 2 | day divider | |
/// | 3 | content of `$ev3` | |
/// | 4 | content of `$ev5` | |
///
/// Note the day divider that is a virtual item. Also note ``$ev4`` which is
/// a reaction to `$ev2`. Finally note that `$ev1` is not rendered in
/// the timeline.
///
/// The mapping between remove event index to timeline item index will look
Hywan marked this conversation as resolved.
Show resolved Hide resolved
/// like this:
///
/// | remove event index | timeline item index | comment |
Hywan marked this conversation as resolved.
Show resolved Hide resolved
/// +--------------------+---------------------+--------------------------------------------+
/// | 0 | `Some(0)` | `$ev0` is rendered as the #0 timeline item |
/// | 1 | `None` | `$ev1` isn't rendered in the timeline |
/// | 2 | `Some(1)` | `$ev2` is rendered as the #1 timeline item |
/// | 3 | `Some(3)` | `$ev3` is rendered as the #3 timeline item |
/// | 4 | `None` | `$ev4` is a reaction to item #1 |
poljar marked this conversation as resolved.
Show resolved Hide resolved
/// | 5 | `Some(4)` | `$ev5` is rendered as the #4 timeline item |
///
/// Note that the #2 timeline item (the day divider) doesn't map to any
/// remote event, but if it moves, it has an impact on this mapping.
pub timeline_item_index: Option<usize>,
}