Skip to content

Commit

Permalink
chore(ui): Clarifies what TimelineItemPosition::UpdateDecrypted holds.
Browse files Browse the repository at this point in the history
This patch tries to clear confusion around
`TimelineItemPosition::UpdateDecrypted(usize)`: it does contains
a timeline item index. This patch changes to
`TimelineItemPosition::UpdateDecrypted { timeline_item_index: usize }`
  • Loading branch information
Hywan committed Nov 27, 2024
1 parent 21f8b7e commit 1c554c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
6 changes: 3 additions & 3 deletions crates/matrix-sdk-ui/src/timeline/controller/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl TimelineState {
let handle_one_res = txn
.handle_remote_event(
event.into(),
TimelineItemPosition::UpdateDecrypted(idx),
TimelineItemPosition::UpdateDecrypted { timeline_item_index: idx },
room_data_provider,
settings,
&mut day_divider_adjuster,
Expand Down Expand Up @@ -451,7 +451,7 @@ impl TimelineStateTransaction<'_> {
TimelineItemPosition::End { origin }
| TimelineItemPosition::Start { origin } => origin,

TimelineItemPosition::UpdateDecrypted(idx) => self
TimelineItemPosition::UpdateDecrypted { timeline_item_index: idx } => self
.items
.get(idx)
.and_then(|item| item.as_event())
Expand Down Expand Up @@ -707,7 +707,7 @@ impl TimelineStateTransaction<'_> {
self.meta.all_events.push_back(event_meta.base_meta());
}

TimelineItemPosition::UpdateDecrypted(_) => {
TimelineItemPosition::UpdateDecrypted { .. } => {
if let Some(event) =
self.meta.all_events.iter_mut().find(|e| e.event_id == event_meta.event_id)
{
Expand Down
28 changes: 20 additions & 8 deletions crates/matrix-sdk-ui/src/timeline/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,26 @@ impl TimelineEventKind {
pub(super) enum TimelineItemPosition {
/// One or more items are prepended to the timeline (i.e. they're the
/// oldest).
Start { origin: RemoteEventOrigin },
Start {
/// The origin of the new item(s).
origin: RemoteEventOrigin,
},

/// One or more items are appended to the timeline (i.e. they're the most
/// recent).
End { origin: RemoteEventOrigin },
End {
/// The origin of the new item(s).
origin: RemoteEventOrigin,
},

/// A single item is updated, after it's been successfully decrypted.
///
/// This happens when an item that was a UTD must be replaced with the
/// decrypted event.
UpdateDecrypted(usize),
UpdateDecrypted {
/// The index of the **timeline item**.
timeline_item_index: usize,
},
}

/// The outcome of handling a single event with
Expand Down Expand Up @@ -481,8 +490,10 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
if !self.result.item_added {
trace!("No new item added");

if let Flow::Remote { position: TimelineItemPosition::UpdateDecrypted(idx), .. } =
self.ctx.flow
if let Flow::Remote {
position: TimelineItemPosition::UpdateDecrypted { timeline_item_index: idx },
..
} = self.ctx.flow
{
// If add was not called, that means the UTD event is one that
// wouldn't normally be visible. Remove it.
Expand Down Expand Up @@ -576,7 +587,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
replacement: PendingEdit,
) {
match position {
TimelineItemPosition::Start { .. } | TimelineItemPosition::UpdateDecrypted(_) => {
TimelineItemPosition::Start { .. } | TimelineItemPosition::UpdateDecrypted { .. } => {
// Only insert the edit if there wasn't any other edit
// before.
//
Expand Down Expand Up @@ -1012,7 +1023,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
| TimelineItemPosition::End { origin } => origin,

// For updates, reuse the origin of the encrypted event.
TimelineItemPosition::UpdateDecrypted(idx) => self.items[idx]
TimelineItemPosition::UpdateDecrypted { timeline_item_index: idx } => self
.items[idx]
.as_event()
.and_then(|ev| Some(ev.as_remote()?.origin))
.unwrap_or_else(|| {
Expand Down Expand Up @@ -1162,7 +1174,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {

Flow::Remote {
event_id: decrypted_event_id,
position: TimelineItemPosition::UpdateDecrypted(idx),
position: TimelineItemPosition::UpdateDecrypted { timeline_item_index: idx },
..
} => {
trace!("Updating timeline item at position {idx}");
Expand Down

0 comments on commit 1c554c4

Please sign in to comment.