Browse Source

fix(ui/chat): add nil guards after Me() calls in message_input.go

Prevent nil pointer dereference panics when state.Cabinet.Me() returns
nil during reconnection. Three call sites in expandMentions and
tabSuggestion now check for nil before accessing me.Username or me.ID.

Fixes COMP #4.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
claude 1 month ago
parent
commit
a0151e6e84
1 changed files with 7 additions and 3 deletions
  1. 7 3
      internal/ui/chat/message_input.go

+ 7 - 3
internal/ui/chat/message_input.go

@@ -316,7 +316,7 @@ func (mi *messageInput) expandMentions(c *discord.Channel, src []byte) []byte {
 			}
 			// self ping
 			me, _ := state.Cabinet.Me()
-			if strings.EqualFold(me.Username, name) {
+			if me != nil && strings.EqualFold(me.Username, name) {
 				return []byte(me.ID.Mention())
 			}
 			return output
@@ -408,7 +408,9 @@ func (mi *messageInput) tabSuggestion() {
 		shown = make(map[string]struct{})
 		// Don't show @me in the list of recent authors
 		me, _ := mi.chat.state.Cabinet.Me()
-		shown[me.Username] = userDone
+		if me != nil {
+			shown[me.Username] = userDone
+		}
 	}
 
 	// DMs have recipients, not members
@@ -428,7 +430,9 @@ func (mi *messageInput) tabSuggestion() {
 		} else {
 			users := selected.DMRecipients
 			me, _ := mi.chat.state.Cabinet.Me()
-			users = append(users, *me)
+			if me != nil {
+				users = append(users, *me)
+			}
 			res := fuzzy.FindFrom(name, userList(users))
 			for _, r := range res {
 				mi.addMentionUser(&users[r.Index])