Selaa lähdekoodia

docs(ui/chat): document reaction handler mutation pattern

Add doc comments on onMessageReactionAdd and onMessageReactionRemove
explaining they mutate msg.Reactions in-place via pointer rather than
using setMessage, and manually invalidate itemByID + invalidateRows.

Fixes: COMP #2, COMP #14

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
claude 1 kuukausi sitten
vanhempi
sitoutus
101d57c7bd
1 muutettua tiedostoa jossa 9 lisäystä ja 0 poistoa
  1. 9 0
      internal/ui/chat/state.go

+ 9 - 0
internal/ui/chat/state.go

@@ -200,6 +200,11 @@ func (m *Model) onTypingStart(event *gateway.TypingStartEvent) {
 	m.addTyper(event.UserID)
 }
 
+// onMessageReactionAdd handles the gateway event for a new reaction on a message.
+// Unlike other event handlers that use setMessage/deleteMessage, this handler mutates
+// msg.Reactions in-place via a pointer into the messages slice, then manually invalidates
+// the itemByID cache entry and calls invalidateRows() to trigger a re-render.
+// This avoids a full message replacement for a small incremental change.
 func (m *Model) onMessageReactionAdd(event *gateway.MessageReactionAddEvent) {
 	selected := m.SelectedChannel()
 	if selected == nil || selected.ID != event.ChannelID {
@@ -239,6 +244,10 @@ func (m *Model) onMessageReactionAdd(event *gateway.MessageReactionAddEvent) {
 	m.messagesList.invalidateRows()
 }
 
+// onMessageReactionRemove handles the gateway event for a removed reaction.
+// Like onMessageReactionAdd, it mutates msg.Reactions in-place via a pointer into
+// the messages slice and manually invalidates the itemByID cache + calls invalidateRows(),
+// rather than using the setMessage path used by other event handlers.
 func (m *Model) onMessageReactionRemove(event *gateway.MessageReactionRemoveEvent) {
 	selected := m.SelectedChannel()
 	if selected == nil || selected.ID != event.ChannelID {