refactor: dedupe attach-files check, drop redundant wrappers

This commit is contained in:
ayn2op 2026-05-17 20:52:10 -04:00
parent 4bc49c52c5
commit 5fae84533d
4 changed files with 11 additions and 13 deletions

View file

@ -749,12 +749,17 @@ func (mi *messageInput) attach(name string, reader io.Reader) {
mi.SetFooter("Attached " + humanJoin(names))
}
func (mi *messageInput) canAttachFiles() bool {
selected := mi.chat.SelectedChannel()
return selected != nil && mi.chat.state.HasPermissions(selected.ID, discord.PermissionAttachFiles)
}
func (mi *messageInput) ShortHelp() []keybind.Keybind {
if mi.chat.GetVisible(mentionsListLayerName) {
cfg := mi.cfg.Keybinds.MentionsList
icfg := mi.cfg.Keybinds.MessageInput
short := []keybind.Keybind{cfg.Up.Keybind, cfg.Down.Keybind, icfg.Cancel.Keybind}
if selected := mi.chat.SelectedChannel(); selected != nil && mi.chat.state.HasPermissions(selected.ID, discord.PermissionAttachFiles) {
if mi.canAttachFiles() {
short = append(short, icfg.OpenFilePicker.Keybind)
}
return short
@ -762,7 +767,7 @@ func (mi *messageInput) ShortHelp() []keybind.Keybind {
cfg := mi.cfg.Keybinds.MessageInput
short := []keybind.Keybind{cfg.Send.Keybind, cfg.Cancel.Keybind, cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
if selected := mi.chat.SelectedChannel(); selected != nil && mi.chat.state.HasPermissions(selected.ID, discord.PermissionAttachFiles) {
if mi.canAttachFiles() {
short = append(short, cfg.OpenFilePicker.Keybind)
}
return short
@ -781,11 +786,8 @@ func (mi *messageInput) FullHelp() [][]keybind.Keybind {
cfg := mi.cfg.Keybinds.MessageInput
openEditor := []keybind.Keybind{cfg.Paste.Keybind, cfg.OpenEditor.Keybind}
selectedChannel := mi.chat.SelectedChannel()
if selectedChannel != nil {
if hasPerm := mi.chat.state.HasPermissions(selectedChannel.ID, discord.PermissionAttachFiles); hasPerm {
openEditor = append(openEditor, cfg.OpenFilePicker.Keybind)
}
if mi.canAttachFiles() {
openEditor = append(openEditor, cfg.OpenFilePicker.Keybind)
}
return [][]keybind.Keybind{

View file

@ -1013,7 +1013,7 @@ func (ml *messagesList) fetchOlderMessages() tview.Cmd {
older := slices.Clone(messages)
slices.Reverse(older)
return newOlderMessagesLoadedMsg(channelID, older)
return olderMessagesLoadedMsg{ChannelID: channelID, Older: older}
}
}

View file

@ -46,10 +46,6 @@ type olderMessagesLoadedMsg struct {
Older []discord.Message
}
func newOlderMessagesLoadedMsg(channelID discord.ChannelID, older []discord.Message) olderMessagesLoadedMsg {
return olderMessagesLoadedMsg{ChannelID: channelID, Older: older}
}
type LogoutMsg struct{}
func (m *Model) logout() tview.Cmd {

View file

@ -51,7 +51,7 @@ func (m *Model) Update(msg tview.Msg) tview.Cmd {
case tview.KeyMsg:
if msg.Key() == tcell.KeyEsc {
m.msg = "Canceled"
return tview.Batch(m.close(), nil)
return m.close()
}
return m.TextView.Update(msg)