Parcourir la source

fix(ui/chat): toggle reactions and refocus messages after emoji pick

Selecting an emoji the user already reacted with now calls Unreact to
remove it. After adding/removing a reaction, focus returns to the
messages list instead of falling through to the guilds panel.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
claude il y a 1 mois
Parent
commit
b1d81f6652
1 fichiers modifiés avec 23 ajouts et 2 suppressions
  1. 23 2
      internal/ui/chat/emoji_picker.go

+ 23 - 2
internal/ui/chat/emoji_picker.go

@@ -195,11 +195,32 @@ func (ep *emojiPicker) HandleEvent(event tview.Event) tview.Command {
 
 		channelID := ep.targetChannelID
 		messageID := ep.targetMessageID
+
+		// Check if user already reacted with this emoji.
+		alreadyReacted := false
+		if msg, err := ep.chatView.state.Cabinet.Message(channelID, messageID); err == nil {
+			for _, r := range msg.Reactions {
+				if r.Me && r.Emoji.APIString() == apiEmoji {
+					alreadyReacted = true
+					break
+				}
+			}
+		}
+
 		ep.chatView.closeEmojiPicker()
 
 		return func() tview.Event {
-			if err := ep.chatView.state.React(channelID, messageID, apiEmoji); err != nil {
-				slog.Error("failed to add reaction", "err", err, "emoji", fmt.Sprint(apiEmoji))
+			if alreadyReacted {
+				if err := ep.chatView.state.Unreact(channelID, messageID, apiEmoji); err != nil {
+					slog.Error("failed to remove reaction", "err", err, "emoji", fmt.Sprint(apiEmoji))
+				}
+			} else {
+				if err := ep.chatView.state.React(channelID, messageID, apiEmoji); err != nil {
+					slog.Error("failed to add reaction", "err", err, "emoji", fmt.Sprint(apiEmoji))
+				}
+			}
+			if cmd := ep.chatView.focusMessagesList(); cmd != nil {
+				return cmd()
 			}
 			return nil
 		}