Skip to content

Commit 92192c5

Browse files
committed
fix(timeline): Remove UTD items that have been decrypted into unsupported events
1 parent 8836004 commit 92192c5

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

crates/matrix-sdk-ui/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ All notable changes to this project will be documented in this file.
3737
- [**breaking**] The MSRV has been bumped to Rust 1.88.
3838
([#5431](https://github.com/matrix-org/matrix-rust-sdk/pull/5431))
3939

40+
### Bug Fixes
41+
42+
- Correctly remove unable-to-decrypt items that have been decrypted but contain
43+
unsupported event types.
44+
([#5463](https://github.com/matrix-org/matrix-rust-sdk/pull/5463))
4045

4146
## [0.13.0] - 2025-07-10
4247

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use ruma::{
2323
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId, UserId,
2424
events::AnySyncTimelineEvent, push::Action, serde::Raw,
2525
};
26-
use tracing::{debug, instrument, warn};
26+
use tracing::{debug, instrument, trace, warn};
2727

2828
use super::{
2929
super::{
@@ -684,7 +684,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
684684
.await;
685685

686686
// Handle the event to create or update a timeline item.
687-
if let Some(timeline_action) = timeline_action {
687+
let item_added = if let Some(timeline_action) = timeline_action {
688688
let sender_profile = room_data_provider.profile_from_user_id(&sender).await;
689689

690690
let ctx = TimelineEventContext {
@@ -715,9 +715,25 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> {
715715
.handle_event(date_divider_adjuster, timeline_action)
716716
.await
717717
} else {
718-
// No item has been removed from the timeline.
718+
// No item has been added to the timeline.
719719
false
720+
};
721+
722+
let mut item_removed = false;
723+
724+
if !item_added {
725+
trace!("No new item added");
726+
727+
if let TimelineItemPosition::UpdateAt { timeline_item_index } = position {
728+
// If add was not called, that means the UTD event is one that
729+
// wouldn't normally be visible. Remove it.
730+
trace!("Removing UTD that was successfully retried");
731+
self.items.remove(timeline_item_index);
732+
item_removed = true;
733+
}
720734
}
735+
736+
item_removed
721737
}
722738

723739
/// Remove one timeline item by its `event_index`.

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
473473

474474
/// Handle an event.
475475
///
476-
/// Returns the number of timeline updates that were made.
476+
/// Returns if an item was added to the timeline due to the new timeline
477+
/// action. Items might not be added to the timeline for various reasons,
478+
/// some common ones are if the item:
479+
/// - Contains an unsupported event type.
480+
/// - Is an edit or a redaction.
481+
/// - Contains a local echo turning into a remote echo.
482+
/// - Contains a message that is already in the timeline but was now
483+
/// decrypted.
477484
///
478485
/// `raw_event` is only needed to determine the cause of any UTDs,
479486
/// so if we know this is not a UTD it can be None.
@@ -482,7 +489,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
482489
mut self,
483490
date_divider_adjuster: &mut DateDividerAdjuster,
484491
timeline_action: TimelineAction,
485-
) -> RemovedItem {
492+
) -> bool {
486493
let span = tracing::Span::current();
487494

488495
date_divider_adjuster.mark_used();
@@ -541,25 +548,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
541548
},
542549
}
543550

544-
let mut removed_item = false;
545-
546-
if !added_item {
547-
trace!("No new item added");
548-
549-
if let Flow::Remote {
550-
position: TimelineItemPosition::UpdateAt { timeline_item_index },
551-
..
552-
} = self.ctx.flow
553-
{
554-
// If add was not called, that means the UTD event is one that
555-
// wouldn't normally be visible. Remove it.
556-
trace!("Removing UTD that was successfully retried");
557-
self.items.remove(timeline_item_index);
558-
removed_item = true;
559-
}
560-
}
561-
562-
removed_item
551+
added_item
563552
}
564553

565554
#[instrument(skip(self, edit_kind))]

0 commit comments

Comments
 (0)