Skip to content

Commit

Permalink
Remove unnecessary TimelineAction via an immediate action handling
Browse files Browse the repository at this point in the history
Now that Timeline and RoomScreen have been merged, we don't need to
emit multiple separate redundant actions for showing the message
being replied to. Instead, we can handle it immediately once
a message widget broadcasts the action that its reply button
has been pressed.
  • Loading branch information
kevinaboos committed Oct 2, 2024
1 parent 763b7e0 commit 5eb9fe0
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,24 +1173,20 @@ impl Widget for RoomScreen {
}

if let Event::Actions(actions) = event {
self.send_user_read_receipts_based_on_scroll_pos(cx, actions);
for action in actions {
// Handle actions on a message, e.g., clicking the reply button or clicking the reply preview.
match action.as_widget_action().cast() {
MessageAction::MessageReply(item_id) => {
let Some(tl) = self.tl_state.as_mut() else {
continue;
};
let tl_idx = item_id as usize;
if let Some(tl_item) = tl.items.get(tl_idx) {
if let Some(tl_event_item) = tl_item.as_event() {
// TODO: this is ugly, but i couldnt find a clean way of making the Message
// dispatch the action itself, it would need access to the timeline state or data
cx.widget_action(
widget_uid,
&scope.path,
TimelineAction::MessageReply(tl_event_item.clone()),
);

if let Some(event_tl_item) = tl.items
.get(item_id)
.and_then(|tl_item| tl_item.as_event().cloned())
{
if let Ok(replied_to_info) = event_tl_item.replied_to_info() {
self.show_replying_to(cx, (event_tl_item, replied_to_info));
}
}
}
Expand Down Expand Up @@ -1251,15 +1247,6 @@ impl Widget for RoomScreen {
}
}

// Handle message reply action
if let TimelineAction::MessageReply(message_to_reply_to) = action.as_widget_action().cast() {
if let Ok(replied_to_info) = message_to_reply_to.replied_to_info() {
self.show_replying_to(cx, (message_to_reply_to, replied_to_info));
} else {
error!("Failed to get replied-to info for message {:?}", message_to_reply_to);
}
}

// Handle the action that requests to show the user profile sliding pane.
if let ShowUserProfileAction::ShowUserProfile(profile_and_room_id) = action.as_widget_action().cast() {
self.show_user_profile(
Expand Down Expand Up @@ -1352,6 +1339,9 @@ impl Widget for RoomScreen {
}
}

// Handle sending any read receipts for the current logged-in user.
self.send_user_read_receipts_based_on_scroll_pos(cx, actions);

// Handle the cancel reply button being clicked.
if self.button(id!(cancel_reply_button)).clicked(&actions) {
self.clear_replying_to();
Expand Down Expand Up @@ -1803,11 +1793,6 @@ impl RoomScreenRef {
}
}

#[derive(Clone, DefaultNone, Debug)]
pub enum TimelineAction {
MessageReply(EventTimelineItem),
None,
}

/// A message that is sent from a background async task to a room's timeline view
/// for the purpose of update the Timeline UI contents or metadata.
Expand Down Expand Up @@ -2183,6 +2168,7 @@ fn populate_message_view(
return (item, new_drawn_status);
}

// Set the Message widget's metatdata for reply-handling purposes.
item.as_message().set_data(
event_tl_item.can_be_replied_to(),
item_id,
Expand Down

0 comments on commit 5eb9fe0

Please sign in to comment.