Commit 7725b07f85

7725b07f85efd9180040177fedc896aec98712c6

parent: 1af5570e47

Unregistered key

vaw <git@nlih.de> · 2026-10-24 23:48 UTC
committer: <noreply@github.com>

Support interactively adding/removing reactions (#835)

Layout: unified · split

src/windows/room/message.rs +61 −1
@@ -7,6 +7,22 @@ use crate::preview::ImageStatus;
77use crate::util::space;
88use crate::windows::room::chat;
99
10fn contains_reaction(
11 info: &RoomInfo,
12 key: &str,
13 message_id: &MessageId,
14 settings: &ApplicationSettings,
15) -> bool {
16 message_id
17 .as_origin()
18 .and_then(|event_id| info.reactions.get(event_id))
19 .is_some_and(|reacts| {
20 reacts
21 .values()
22 .any(|(k, user, _)| user == &settings.profile.user_id && k == key)
23 })
24}
25
1026/// State needed for rendering [MessageWidget].
1127pub(crate) struct MessageState {
1228 room: MatrixRoom,
@@ -347,6 +363,12 @@ impl StatefulWidget for MessageWidget<'_> {
347363 }
348364
349365 let section = Cow::from(content);
366 items.push(MessageInfoItem::Reaction(
367 section.clone(),
368 key.to_string(),
369 state.room_id().to_owned(),
370 state.id(),
371 ));
350372 items.extend(users.into_iter().map(|user_id| {
351373 MessageInfoItem::User(
352374 section.clone(),
@@ -447,6 +469,9 @@ pub(crate) enum MessageInfoItem {
447469 /// The message itself
448470 Message(OwnedRoomId, MessageId),
449471
472 /// The line to interactively un-/react
473 Reaction(Cow<'static, str>, String, OwnedRoomId, MessageId),
474
450475 User(Cow<'static, str>, OwnedRoomId, OwnedUserId),
451476 Link(char, Url),
452477}
@@ -463,6 +488,7 @@ impl Display for MessageInfoItem {
463488 write!(f, "{user_id}")
464489 },
465490 MessageInfoItem::Link(_, url) => write!(f, "{url}"),
491 MessageInfoItem::Reaction(_, key, ..) => write!(f, "{key}"),
466492 }
467493 }
468494}
@@ -545,6 +571,17 @@ impl ListItem<IambInfo> for MessageInfoItem {
545571 MessageInfoItem::Link(c, url) => {
546572 Text::from(Span::styled(format!("[{c}] {url}"), style.bold()))
547573 },
574 MessageInfoItem::Reaction(_, key, room_id, message_id) => {
575 let Some(info) = store.application.rooms.get(room_id) else {
576 return Span::styled("Loading room...", style.fg(Color::Gray)).into();
577 };
578
579 if contains_reaction(info, key, message_id, &store.application.settings) {
580 Text::from(Span::styled(format!("Press Enter to unreact with '{key}'"), style))
581 } else {
582 Text::from(Span::styled(format!("Press Enter to react with '{key}'"), style))
583 }
584 },
548585 }
549586 }
550587
@@ -558,6 +595,7 @@ impl ListItem<IambInfo> for MessageInfoItem {
558595 Some(user_id.to_string())
559596 },
560597 MessageInfoItem::Link(.., url) => Some(url.to_string()),
598 MessageInfoItem::Reaction(_, key, ..) => Some(key.to_string()),
561599 }
562600 }
563601
@@ -566,6 +604,7 @@ impl ListItem<IambInfo> for MessageInfoItem {
566604 MessageInfoItem::Header(..) | MessageInfoItem::Message(..) => None,
567605 MessageInfoItem::User(section, ..) => Some(section),
568606 MessageInfoItem::Link(..) => Some(&Cow::Borrowed("Links:")),
607 MessageInfoItem::Reaction(section, ..) => Some(section),
569608 }
570609 }
571610}
@@ -575,7 +614,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for MessageInfoItem {
575614 &mut self,
576615 act: &PromptAction,
577616 ctx: &ProgramContext,
578 _: &mut ProgramStore,
617 store: &mut ProgramStore,
579618 ) -> EditResult<Vec<(ProgramAction, ProgramContext)>, IambInfo> {
580619 match act {
581620 PromptAction::Submit => {
@@ -604,6 +643,27 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for MessageInfoItem {
604643 let act = IambAction::OpenLink(url.to_string());
605644 Ok(vec![(act.into(), ctx.clone())])
606645 },
646 MessageInfoItem::Reaction(_, key, room_id, message_id) => {
647 let Some(info) = store.application.rooms.get(room_id) else {
648 let msg = "Room not loaded.";
649 let err = EditError::Failure(msg.into());
650
651 return Err(err);
652 };
653
654 let act = if contains_reaction(
655 info,
656 key,
657 message_id,
658 &store.application.settings,
659 ) {
660 MessageAction::Unreact(Some(key.to_string()), true)
661 } else {
662 MessageAction::React(key.to_string(), true)
663 };
664 let act: IambAction = act.into();
665 Ok(vec![(act.into(), ctx.clone())])
666 },
607667 }
608668 },
609669 PromptAction::Abort(..) => {