@@ -138,30 +138,44 @@ pub(super) enum HandleAggregationKind {
138
138
PollEnd ,
139
139
}
140
140
141
+ /// An action that we want to cause on the timeline.
141
142
#[ 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
+ } ,
144
155
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
+ } ,
146
167
}
147
168
148
- impl TimelineEventKind {
169
+ impl TimelineAction {
149
170
/// Create a new [`TimelineEventKind::AddItem`] with no edit json.
150
171
fn add_item ( content : TimelineItemContent ) -> Self {
151
172
Self :: AddItem { content, edit_json : None }
152
173
}
153
174
154
- /// Creates a new `TimelineEventKind`.
155
- ///
156
- /// # Arguments
175
+ /// Create a new [`TimelineAction`] from a given remote event.
157
176
///
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.
165
179
pub async fn from_event < P : RoomDataProvider > (
166
180
event : AnySyncTimelineEvent ,
167
181
raw_event : & Raw < AnySyncTimelineEvent > ,
@@ -274,6 +288,14 @@ impl TimelineEventKind {
274
288
} )
275
289
}
276
290
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.
277
299
pub ( super ) fn from_content (
278
300
content : AnyMessageLikeEventContent ,
279
301
raw_event : Option < & Raw < AnySyncTimelineEvent > > ,
@@ -588,7 +610,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
588
610
pub ( super ) async fn handle_event (
589
611
mut self ,
590
612
date_divider_adjuster : & mut DateDividerAdjuster ,
591
- event_kind : TimelineEventKind ,
613
+ event_kind : TimelineAction ,
592
614
) -> HandleEventResult {
593
615
let span = tracing:: Span :: current ( ) ;
594
616
@@ -611,13 +633,13 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
611
633
} ;
612
634
613
635
match event_kind {
614
- TimelineEventKind :: AddItem { content, edit_json } => {
636
+ TimelineAction :: AddItem { content, edit_json } => {
615
637
if self . ctx . should_add_new_items {
616
638
self . add_item ( content, edit_json) ;
617
639
}
618
640
}
619
641
620
- TimelineEventKind :: HandleAggregation { related_event, kind } => match kind {
642
+ TimelineAction :: HandleAggregation { related_event, kind } => match kind {
621
643
HandleAggregationKind :: Reaction { key } => {
622
644
self . handle_reaction ( related_event, key) ;
623
645
}
0 commit comments