Skip to content

Commit 01d45e7

Browse files
committed
refactor(timeline): rename TimelineEventKind into TimelineAction and add comments
1 parent 4d74299 commit 01d45e7

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

crates/matrix-sdk-ui/src/timeline/controller/state.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ use super::{
3434
super::{
3535
date_dividers::DateDividerAdjuster,
3636
event_handler::{
37-
Flow, TimelineEventContext, TimelineEventHandler, TimelineEventKind,
38-
TimelineItemPosition,
37+
Flow, TimelineAction, TimelineEventContext, TimelineEventHandler, TimelineItemPosition,
3938
},
4039
event_item::RemoteEventOrigin,
4140
traits::RoomDataProvider,
@@ -164,11 +163,11 @@ impl TimelineState {
164163

165164
let mut date_divider_adjuster = DateDividerAdjuster::new(date_divider_mode);
166165

167-
if let Some(timeline_event_kind) =
168-
TimelineEventKind::from_content(content, None, None, None, &txn.items, &mut txn.meta)
166+
if let Some(timeline_action) =
167+
TimelineAction::from_content(content, None, None, None, &txn.items, &mut txn.meta)
169168
{
170169
TimelineEventHandler::new(&mut txn, ctx)
171-
.handle_event(&mut date_divider_adjuster, timeline_event_kind)
170+
.handle_event(&mut date_divider_adjuster, timeline_action)
172171
.await;
173172
txn.adjust_date_dividers(date_divider_adjuster);
174173
}

crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use super::{
2525
controller::{FullEventMeta, ObservableItemsTransactionEntry},
2626
date_dividers::DateDividerAdjuster,
2727
event_handler::{
28-
Flow, HandleEventResult, TimelineEventContext, TimelineEventHandler, TimelineEventKind,
28+
Flow, HandleEventResult, TimelineEventContext, TimelineEventHandler,
2929
TimelineItemPosition,
3030
},
3131
event_item::RemoteEventOrigin,
@@ -34,7 +34,10 @@ use super::{
3434
ObservableItems, ObservableItemsTransaction, TimelineFocusKind, TimelineMetadata,
3535
TimelineSettings,
3636
};
37-
use crate::{events::SyncTimelineEventWithoutContent, timeline::VirtualTimelineItem};
37+
use crate::{
38+
events::SyncTimelineEventWithoutContent,
39+
timeline::{event_handler::TimelineAction, VirtualTimelineItem},
40+
};
3841

3942
pub(in crate::timeline) struct TimelineStateTransaction<'a> {
4043
/// A vector transaction over the items themselves. Holds temporary state
@@ -312,7 +315,7 @@ impl<'a> TimelineStateTransaction<'a> {
312315
event.sender().to_owned(),
313316
event.origin_server_ts(),
314317
event.transaction_id().map(ToOwned::to_owned),
315-
TimelineEventKind::from_event(
318+
TimelineAction::from_event(
316319
event,
317320
&raw,
318321
room_data_provider,
@@ -334,7 +337,7 @@ impl<'a> TimelineStateTransaction<'a> {
334337
event.sender().to_owned(),
335338
event.origin_server_ts(),
336339
event.transaction_id().map(ToOwned::to_owned),
337-
Some(TimelineEventKind::failed_to_parse(event, e)),
340+
Some(TimelineAction::failed_to_parse(event, e)),
338341
true,
339342
),
340343

crates/matrix-sdk-ui/src/timeline/event_handler.rs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,44 @@ pub(super) enum HandleAggregationKind {
138138
PollEnd,
139139
}
140140

141+
/// An action that we want to cause on the timeline.
141142
#[derive(Clone, Debug)]
142-
pub(super) enum TimelineEventKind {
143-
AddItem { content: TimelineItemContent, edit_json: Option<Raw<AnySyncTimelineEvent>> },
143+
pub(super) enum TimelineAction {
144+
/// Add a new timeline item.
145+
///
146+
/// This enqueues adding a new item to the timeline (i.e. push to the items
147+
/// array in its state). The item may be filtered out, and thus not
148+
/// added later.
149+
AddItem {
150+
/// The content of the item we want to add.
151+
content: TimelineItemContent,
152+
/// The latest edit JSON for this item.
153+
edit_json: Option<Raw<AnySyncTimelineEvent>>,
154+
},
144155

145-
HandleAggregation { related_event: OwnedEventId, kind: HandleAggregationKind },
156+
/// Handle an aggregation to another event.
157+
///
158+
/// The event the aggregation is related to might not be included in the
159+
/// timeline, in which case it will be stashed somewhere, until we see
160+
/// the related event.
161+
HandleAggregation {
162+
/// To which other event does this aggregation apply to?
163+
related_event: OwnedEventId,
164+
/// What kind of aggregation are we handling here?
165+
kind: HandleAggregationKind,
166+
},
146167
}
147168

148-
impl TimelineEventKind {
169+
impl TimelineAction {
149170
/// Create a new [`TimelineEventKind::AddItem`] with no edit json.
150171
fn add_item(content: TimelineItemContent) -> Self {
151172
Self::AddItem { content, edit_json: None }
152173
}
153174

154-
/// Creates a new `TimelineEventKind`.
155-
///
156-
/// # Arguments
175+
/// Create a new [`TimelineAction`] from a given remote event.
157176
///
158-
/// * `event` - The event for which we should create a `TimelineEventKind`.
159-
/// * `raw_event` - The [`Raw`] JSON for `event`. (Required so that we can
160-
/// access `unsigned` data.)
161-
/// * `room_data_provider` - An object which will provide information about
162-
/// the room containing the event.
163-
/// * `unable_to_decrypt_info` - If `event` represents a failure to decrypt,
164-
/// information about that failure. Otherwise, `None`.
177+
/// The return value may be `None` if handling the event (be it a new item
178+
/// or an aggregation) is not supported for this event type.
165179
pub async fn from_event<P: RoomDataProvider>(
166180
event: AnySyncTimelineEvent,
167181
raw_event: &Raw<AnySyncTimelineEvent>,
@@ -274,6 +288,14 @@ impl TimelineEventKind {
274288
})
275289
}
276290

291+
/// Create a new [`TimelineAction`] from a given event's content.
292+
///
293+
/// This is applicable to both remote event (as this is called from
294+
/// [`TimelineAction::from_event`]) or local events (for which we only have
295+
/// the content).
296+
///
297+
/// The return value may be `None` if handling the event (be it a new item
298+
/// or an aggregation) is not supported for this event type.
277299
pub(super) fn from_content(
278300
content: AnyMessageLikeEventContent,
279301
raw_event: Option<&Raw<AnySyncTimelineEvent>>,
@@ -588,7 +610,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
588610
pub(super) async fn handle_event(
589611
mut self,
590612
date_divider_adjuster: &mut DateDividerAdjuster,
591-
event_kind: TimelineEventKind,
613+
event_kind: TimelineAction,
592614
) -> HandleEventResult {
593615
let span = tracing::Span::current();
594616

@@ -611,13 +633,13 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
611633
};
612634

613635
match event_kind {
614-
TimelineEventKind::AddItem { content, edit_json } => {
636+
TimelineAction::AddItem { content, edit_json } => {
615637
if self.ctx.should_add_new_items {
616638
self.add_item(content, edit_json);
617639
}
618640
}
619641

620-
TimelineEventKind::HandleAggregation { related_event, kind } => match kind {
642+
TimelineAction::HandleAggregation { related_event, kind } => match kind {
621643
HandleAggregationKind::Reaction { key } => {
622644
self.handle_reaction(related_event, key);
623645
}

0 commit comments

Comments
 (0)