Skip to content

Commit

Permalink
timeline: rename variables around reaction redaction
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjbvr committed Apr 19, 2024
1 parent 071592c commit 9b5f2f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
9 changes: 5 additions & 4 deletions crates/matrix-sdk-ui/src/timeline/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ pub(super) enum TimelineEventKind {
relations: BundledMessageLikeRelations<AnySyncMessageLikeEvent>,
},

/// 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.
Expand Down
29 changes: 17 additions & 12 deletions crates/matrix-sdk-ui/src/timeline/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnedEventId>),
/// 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),
}

Expand Down Expand Up @@ -277,7 +283,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
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 =
Expand All @@ -295,10 +301,9 @@ impl<P: RoomDataProvider> TimelineInner<P> {

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::<AnnotationKey>(&annotation.into());
let txn_id = match in_flight {
Expand All @@ -321,24 +326,24 @@ impl<P: RoomDataProvider> TimelineInner<P> {
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())
}
};

Expand Down

0 comments on commit 9b5f2f0

Please sign in to comment.