@@ -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+ timeline_action : TimelineAction ,
592614 ) -> HandleEventResult {
593615 let span = tracing:: Span :: current ( ) ;
594616
@@ -610,14 +632,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
610632 }
611633 } ;
612634
613- match event_kind {
614- TimelineEventKind :: AddItem { content, edit_json } => {
635+ match timeline_action {
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