refactor(ui/chat): move processText and expandMentions to messageInput struct (#733)

This commit is contained in:
Ayyan 2026-02-01 18:16:35 -05:00 • committed by GitHub
parent 6f5a1c36cb
commit 5f884cdf28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 10 deletions

View file

@ -199,7 +199,7 @@ func (mi *messageInput) send() {
}
}()
text = processText(mi.chatView.state, selected, []byte(text))
text = mi.processText(selected, []byte(text))
if mi.edit {
m, err := mi.chatView.messagesList.selectedMessage()
@ -231,7 +231,7 @@ func (mi *messageInput) send() {
mi.chatView.messagesList.ScrollToEnd()
}
func processText(state *ningen.State, channel *discord.Channel, src []byte) string {
func (mi *messageInput) processText(channel *discord.Channel, src []byte) string {
// Fast path: no mentions to expand.
if bytes.IndexByte(src, '@') == -1 {
return string(src)
@ -239,7 +239,7 @@ func processText(state *ningen.State, channel *discord.Channel, src []byte) stri
// Fast path: no back ticks (code blocks), so expand mentions directly.
if bytes.IndexByte(src, '`') == -1 {
return string(expandMentions(state, channel, src))
return string(mi.expandMentions(channel, src))
}
var (
@ -265,13 +265,14 @@ func processText(state *ningen.State, channel *discord.Channel, src []byte) stri
})
for _, rng := range ranges {
src = slices.Replace(src, rng[0], rng[1], expandMentions(state, channel, src[rng[0]:rng[1]])...)
src = slices.Replace(src, rng[0], rng[1], mi.expandMentions(channel, src[rng[0]:rng[1]])...)
}
return string(src)
}
func expandMentions(state *ningen.State, c *discord.Channel, src []byte) []byte {
func (mi *messageInput) expandMentions(c *discord.Channel, src []byte) []byte {
state := mi.chatView.state
return mentionRegex.ReplaceAllFunc(src, func(input []byte) []byte {
output := input
name := string(input[1:])

View file

@ -665,11 +665,6 @@ func (ml *messagesList) delete() {
if msg.GuildID.IsValid() {
me, _ := ml.chatView.state.Cabinet.Me()
if err != nil {
slog.Error("failed to get client user (me)", "err", err)
return
}
if msg.Author.ID != me.ID && !ml.chatView.state.HasPermissions(msg.ChannelID, discord.PermissionManageMessages) {
slog.Error("failed to delete message; missing relevant permissions", "channel_id", msg.ChannelID, "message_id", msg.ID)
return