@@ -354,12 +354,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
354
354
self . handle_room_message_edit ( re) ;
355
355
}
356
356
AnyMessageLikeEventContent :: RoomMessage ( c) => {
357
- self . add ( should_add, TimelineItemContent :: message ( c, relations, self . items ) ) ;
357
+ if should_add {
358
+ self . add_new_item ( TimelineItemContent :: message ( c, relations, self . items ) ) ;
359
+ }
358
360
}
359
361
AnyMessageLikeEventContent :: RoomEncrypted ( c) => {
360
362
// TODO: Handle replacements if the replaced event is also UTD
361
363
let cause = UtdCause :: determine ( raw_event) ;
362
- self . add ( true , TimelineItemContent :: unable_to_decrypt ( c, cause) ) ;
364
+ self . add_new_item ( TimelineItemContent :: unable_to_decrypt ( c, cause) ) ;
363
365
364
366
// Let the hook know that we ran into an unable-to-decrypt that is added to the
365
367
// timeline.
@@ -370,7 +372,9 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
370
372
}
371
373
}
372
374
AnyMessageLikeEventContent :: Sticker ( content) => {
373
- self . add ( should_add, TimelineItemContent :: Sticker ( Sticker { content } ) ) ;
375
+ if should_add {
376
+ self . add_new_item ( TimelineItemContent :: Sticker ( Sticker { content } ) ) ;
377
+ }
374
378
}
375
379
AnyMessageLikeEventContent :: UnstablePollStart (
376
380
UnstablePollStartEventContent :: Replacement ( c) ,
@@ -381,10 +385,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
381
385
AnyMessageLikeEventContent :: UnstablePollResponse ( c) => self . handle_poll_response ( c) ,
382
386
AnyMessageLikeEventContent :: UnstablePollEnd ( c) => self . handle_poll_end ( c) ,
383
387
AnyMessageLikeEventContent :: CallInvite ( _) => {
384
- self . add ( should_add, TimelineItemContent :: CallInvite ) ;
388
+ if should_add {
389
+ self . add_new_item ( TimelineItemContent :: CallInvite ) ;
390
+ }
385
391
}
386
392
AnyMessageLikeEventContent :: CallNotify ( _) => {
387
- self . add ( should_add, TimelineItemContent :: CallNotify )
393
+ if should_add {
394
+ self . add_new_item ( TimelineItemContent :: CallNotify )
395
+ }
388
396
}
389
397
390
398
// TODO
@@ -397,8 +405,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
397
405
} ,
398
406
399
407
TimelineEventKind :: RedactedMessage { event_type } => {
400
- if event_type != MessageLikeEventType :: Reaction {
401
- self . add ( should_add , TimelineItemContent :: RedactedMessage ) ;
408
+ if event_type != MessageLikeEventType :: Reaction && should_add {
409
+ self . add_new_item ( TimelineItemContent :: RedactedMessage ) ;
402
410
}
403
411
}
404
412
@@ -410,28 +418,37 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
410
418
}
411
419
412
420
TimelineEventKind :: RoomMember { user_id, content, sender } => {
413
- self . add ( should_add, TimelineItemContent :: room_member ( user_id, content, sender) ) ;
421
+ if should_add {
422
+ self . add_new_item ( TimelineItemContent :: room_member ( user_id, content, sender) ) ;
423
+ }
414
424
}
415
425
416
426
TimelineEventKind :: OtherState { state_key, content } => {
417
- self . add (
418
- should_add,
419
- TimelineItemContent :: OtherState ( OtherState { state_key, content } ) ,
420
- ) ;
427
+ if should_add {
428
+ self . add_new_item ( TimelineItemContent :: OtherState ( OtherState {
429
+ state_key,
430
+ content,
431
+ } ) ) ;
432
+ }
421
433
}
422
434
423
435
TimelineEventKind :: FailedToParseMessageLike { event_type, error } => {
424
- self . add (
425
- should_add,
426
- TimelineItemContent :: FailedToParseMessageLike { event_type, error } ,
427
- ) ;
436
+ if should_add {
437
+ self . add_new_item ( TimelineItemContent :: FailedToParseMessageLike {
438
+ event_type,
439
+ error,
440
+ } ) ;
441
+ }
428
442
}
429
443
430
444
TimelineEventKind :: FailedToParseState { event_type, state_key, error } => {
431
- self . add (
432
- should_add,
433
- TimelineItemContent :: FailedToParseState { event_type, state_key, error } ,
434
- ) ;
445
+ if should_add {
446
+ self . add_new_item ( TimelineItemContent :: FailedToParseState {
447
+ event_type,
448
+ state_key,
449
+ error,
450
+ } ) ;
451
+ }
435
452
}
436
453
}
437
454
@@ -636,7 +653,10 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
636
653
// don't have an event ID that could be referenced by responses yet.
637
654
self . meta . poll_pending_events . apply ( & event_id, & mut poll_state) ;
638
655
}
639
- self . add ( should_add, TimelineItemContent :: Poll ( poll_state) ) ;
656
+
657
+ if should_add {
658
+ self . add_new_item ( TimelineItemContent :: Poll ( poll_state) ) ;
659
+ }
640
660
}
641
661
642
662
fn handle_poll_response ( & mut self , c : UnstablePollResponseEventContent ) {
@@ -846,11 +866,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
846
866
}
847
867
848
868
/// Add a new event item in the timeline.
849
- fn add ( & mut self , should_add : bool , content : TimelineItemContent ) {
850
- if !should_add {
851
- return ;
852
- }
853
-
869
+ fn add_new_item ( & mut self , content : TimelineItemContent ) {
854
870
self . result . item_added = true ;
855
871
856
872
let sender = self . ctx . sender . to_owned ( ) ;
@@ -859,12 +875,10 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
859
875
let mut reactions = self . pending_reactions ( ) . unwrap_or_default ( ) ;
860
876
861
877
let kind: EventTimelineItemKind = match & self . ctx . flow {
862
- Flow :: Local { txn_id, abort_handle } => {
863
- LocalEventTimelineItem {
864
- send_state : EventSendState :: NotSentYet ,
865
- transaction_id : txn_id. to_owned ( ) ,
866
- abort_handle : abort_handle. clone ( ) ,
867
- }
878
+ Flow :: Local { txn_id, abort_handle } => LocalEventTimelineItem {
879
+ send_state : EventSendState :: NotSentYet ,
880
+ transaction_id : txn_id. to_owned ( ) ,
881
+ abort_handle : abort_handle. clone ( ) ,
868
882
}
869
883
. into ( ) ,
870
884
0 commit comments