commit 9933923

sewn  ·  2026-08-17 22:46:26 +0000 UTC
parent 07507a9
Allow removing reactions
4 files changed,  +16, -4
+5, -1
 1@@ -7,6 +7,7 @@ import (
 2 	"net/url"
 3 	"os"
 4 	"path/filepath"
 5+	"slices"
 6 	"sort"
 7 	"strconv"
 8 	"strings"
 9@@ -365,7 +366,10 @@ func noCommand(app *App, content string) error {
10 	line, flag := app.win.SelectedMessage()
11 
12 	if line != nil && flag == ui.MessageReact {
13-		s.React(buffer, line.ID, content)
14+		removal := slices.ContainsFunc(line.Reacts, func(r ui.React) bool {
15+			return r.React == content
16+		})
17+		s.React(buffer, line.ID, content, removal)
18 		app.win.ClearMessageSelection()
19 		if !s.HasCapability("echo-message") {
20 			app.win.ApplyReact(netID, buffer, line.ID, s.Nick(), content, false)
+1, -1
1@@ -263,7 +263,7 @@ shortcuts {
2 |  message-select-next
3 :  select the next message in the timeline
4 |  message-react
5-:  mark the selected message as reacting to using the editor
6+:  mark the selected message as reacting to using the editor, reacting twice will remove
7 |  message-reply
8 :  copy the selected message as replying to using the editor
9 |  message-copy
+6, -2
 1@@ -562,13 +562,17 @@ func (s *Session) PrivMsgReply(target, content, replyTo string) {
 2 	delete(s.typingStamps, targetCf)
 3 }
 4 
 5-func (s *Session) React(target, msgid, react string) {
 6+func (s *Session) React(target, msgid, react string, removal bool) {
 7 	if !s.HasCapability("message-tags") || !s.CanSendTag("draft/react") {
 8 		return
 9 	}
10+	tag := "+draft/react"
11+	if removal {
12+		tag = "+draft/unreact"
13+	}
14 	s.out <- NewMessage("TAGMSG", target).
15 		WithTag("+draft/reply", msgid).
16-		WithTag("+draft/react", react)
17+		WithTag(tag, react)
18 }
19 
20 func (s *Session) Typing(target string) {
+4, -0
 1@@ -611,6 +611,10 @@ func (l *Line) ApplyReact(user, react string, removal bool) {
 2 		}
 3 		if !removal {
 4 			us = append(us, user)
 5+		} else if len(us) == 0 {
 6+			// No users remaining
 7+			l.Reacts = append(l.Reacts[:i], l.Reacts[i+1:]...)
 8+			return
 9 		}
10 		l.Reacts[i].Users = us
11 		return