refactor(ui/chat): move processText and expandMentions to messageInput struct (#733)
This commit is contained in:
parent
6f5a1c36cb
commit
5f884cdf28
2 changed files with 6 additions and 10 deletions
|
|
@ -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:])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue