From 9b5f2f098712136b0c86a3041e8a2e72f4fe7c15 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Fri, 19 Apr 2024 12:37:19 +0200 Subject: [PATCH] timeline: rename variables around reaction redaction --- .../src/timeline/event_handler.rs | 9 +++--- .../matrix-sdk-ui/src/timeline/inner/mod.rs | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index 8b5adcb573b..5f009f85a6a 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -107,12 +107,13 @@ pub(super) enum TimelineEventKind { relations: BundledMessageLikeRelations, }, - /// Some event that was redacted a priori, i.e. we never had the original - /// content, so we'll just display a dummy redacted timeline item. + /// Some remote event that was redacted a priori, i.e. we never had the + /// original content, so we'll just display a dummy redacted timeline + /// item. RedactedMessage { event_type: MessageLikeEventType }, - /// We're redacting an event that we may or may not know about (i.e. the - /// redacted event *may* have a corresponding timeline item). + /// We're redacting a remote event that we may or may not know about (i.e. + /// the redacted event *may* have a corresponding timeline item). Redaction { redacts: OwnedEventId }, /// A redaction of a local echo. diff --git a/crates/matrix-sdk-ui/src/timeline/inner/mod.rs b/crates/matrix-sdk-ui/src/timeline/inner/mod.rs index 001cf8aa9ea..36a15846fbf 100644 --- a/crates/matrix-sdk-ui/src/timeline/inner/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/inner/mod.rs @@ -92,7 +92,13 @@ pub(super) enum ReactionAction { #[derive(Debug, Clone)] pub(super) enum ReactionState { + /// We're redacting an reaction. + /// + /// The optional event id is defined if, and only if, there already was a + /// remote echo for this reaction. Redacting(Option), + /// We're sending the reaction with the given transaction id, which we'll + /// use to match against the response in the sync event. Sending(OwnedTransactionId), } @@ -277,7 +283,7 @@ impl TimelineInner

{ item.to_owned() }; - let (to_redact_local, to_redact_remote) = { + let (local_echo_txn_id, remote_echo_event_id) = { let reactions = related_event.reactions(); let user_reactions = @@ -295,10 +301,9 @@ impl TimelineInner

{ let sender = self.room_data_provider.own_user_id().to_owned(); let sender_profile = self.room_data_provider.profile_from_user_id(&sender).await; - let reaction_state = match (to_redact_local, to_redact_remote) { + let reaction_state = match (local_echo_txn_id, remote_echo_event_id) { (None, None) => { // No previous record of the reaction, create a local echo. - let in_flight = state.meta.in_flight_reaction.get::(&annotation.into()); let txn_id = match in_flight { @@ -321,24 +326,24 @@ impl TimelineInner

{ relations: Default::default(), }, ); + ReactionState::Sending(txn_id) } - (to_redact_local, to_redact_remote) => { - // The reaction exists, redact local echo and/or remote echo - - let content = if let Some(to_redact_local) = to_redact_local { - TimelineEventKind::LocalRedaction { redacts: to_redact_local.clone() } - } else if let Some(to_redact_remote) = to_redact_remote { - TimelineEventKind::Redaction { redacts: to_redact_remote.clone() } + (local_echo_txn_id, remote_echo_event_id) => { + // The reaction exists, redact local echo and/or remote echo. + let content = if let Some(txn_id) = local_echo_txn_id { + TimelineEventKind::LocalRedaction { redacts: txn_id.clone() } + } else if let Some(event_id) = remote_echo_event_id { + TimelineEventKind::Redaction { redacts: event_id.clone() } } else { unreachable!("the None/None case has been handled above") }; state.handle_local_event(sender, sender_profile, TransactionId::new(), content); - // Remember the remote echo to redact on the homeserver - ReactionState::Redacting(to_redact_remote.cloned()) + // Remember the remote echo to redact on the homeserver. + ReactionState::Redacting(remote_echo_event_id.cloned()) } };