feat(ui): implement message actions list (#111)
This commit is contained in:
parent
a6fa21b751
commit
5b362d7c4f
4 changed files with 78 additions and 63 deletions
|
|
@ -13,19 +13,16 @@ type GeneralConfig struct {
|
|||
}
|
||||
|
||||
type KeybindingsConfig struct {
|
||||
FocusGuildsList []string `json:"focusGuildsList"`
|
||||
FocusChannelsTreeView []string `json:"focusChannelsTreeView"`
|
||||
FocusMessagesTextView []string `json:"focusMessagesTextView"`
|
||||
FocusMessageInputField []string `json:"focusMessageInputField"`
|
||||
FocusGuildsList []string `json:"focusGuildsList"`
|
||||
FocusChannelsTreeView []string `json:"focusChannelsTreeView"`
|
||||
FocusMessagesTextView []string `json:"focusMessagesTextView"`
|
||||
FocusMessageInputField []string `json:"focusMessageInputField"`
|
||||
FocusMessageActionsList []string `json:"focusMessageActionsList"`
|
||||
|
||||
SelectPreviousMessage []string `json:"selectPreviousMessage"`
|
||||
SelectNextMessage []string `json:"selectNextMessage"`
|
||||
SelectFirstMessage []string `json:"selectFirstMessage"`
|
||||
SelectLastMessage []string `json:"selectLastMessage"`
|
||||
SelectMessageReference []string `json:"selectMessageReference"`
|
||||
ReplySelectedMessage []string `json:"replySelectedMessage"`
|
||||
MentionReplySelectedMessage []string `json:"mentionReplySelectedMessage"`
|
||||
CopySelectedMessage []string `json:"copySelectedMessage"`
|
||||
SelectPreviousMessage []string `json:"selectPreviousMessage"`
|
||||
SelectNextMessage []string `json:"selectNextMessage"`
|
||||
SelectFirstMessage []string `json:"selectFirstMessage"`
|
||||
SelectLastMessage []string `json:"selectLastMessage"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
|
@ -42,19 +39,16 @@ func New() *Config {
|
|||
Notifications: true,
|
||||
},
|
||||
Keybindings: KeybindingsConfig{
|
||||
FocusGuildsList: []string{"Alt+Rune[g]"},
|
||||
FocusChannelsTreeView: []string{"Alt+Rune[t]"},
|
||||
FocusMessagesTextView: []string{"Alt+Rune[m]"},
|
||||
FocusMessageInputField: []string{"Alt+Rune[i]"},
|
||||
FocusGuildsList: []string{"Alt+Rune[g]"},
|
||||
FocusChannelsTreeView: []string{"Alt+Rune[t]"},
|
||||
FocusMessagesTextView: []string{"Alt+Rune[m]"},
|
||||
FocusMessageInputField: []string{"Alt+Rune[i]"},
|
||||
FocusMessageActionsList: []string{"Alt+Rune[a]"},
|
||||
|
||||
SelectPreviousMessage: []string{"Up"},
|
||||
SelectNextMessage: []string{"Down"},
|
||||
SelectFirstMessage: []string{"Home"},
|
||||
SelectLastMessage: []string{"End"},
|
||||
SelectMessageReference: []string{"Rune[m]"},
|
||||
ReplySelectedMessage: []string{"Rune[r]"},
|
||||
MentionReplySelectedMessage: []string{"Rune[R]"},
|
||||
CopySelectedMessage: []string{"Rune[c]"},
|
||||
SelectPreviousMessage: []string{"Up"},
|
||||
SelectNextMessage: []string{"Down"},
|
||||
SelectFirstMessage: []string{"Home"},
|
||||
SelectLastMessage: []string{"End"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
type App struct {
|
||||
*tview.Application
|
||||
MainFlex *tview.Flex
|
||||
GuildsList *tview.List
|
||||
ChannelsTreeView *tview.TreeView
|
||||
MessagesTextView *tview.TextView
|
||||
|
|
|
|||
|
|
@ -187,59 +187,77 @@ func onMessagesTextViewInputCapture(app *App, e *tcell.EventKey) *tcell.EventKey
|
|||
Highlight(ms[app.SelectedMessage].ID).
|
||||
ScrollToHighlight()
|
||||
return nil
|
||||
} else if util.HasKeybinding(app.Config.Keybindings.SelectMessageReference, e.Name()) {
|
||||
} else if util.HasKeybinding(app.Config.Keybindings.FocusMessageActionsList, e.Name()) {
|
||||
messageActionsList := tview.NewList()
|
||||
|
||||
hs := app.MessagesTextView.GetHighlights()
|
||||
if len(hs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, m := util.FindMessageByID(app.SelectedChannel.Messages, hs[0])
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if util.HasPermission(app.Session.State, app.SelectedChannel.ID, discordgo.PermissionManageMessages) || m.Author.ID == app.Session.State.User.ID {
|
||||
messageActionsList.AddItem("Edit", "", 'e', nil)
|
||||
}
|
||||
|
||||
if util.HasPermission(app.Session.State, app.SelectedChannel.ID, discordgo.PermissionSendMessages) {
|
||||
messageActionsList.AddItem("Reply", "", 'r', nil)
|
||||
messageActionsList.AddItem("Mention Reply", "", 'R', nil)
|
||||
}
|
||||
|
||||
if m.ReferencedMessage != nil {
|
||||
app.SelectedMessage, _ = util.FindMessageByID(app.SelectedChannel.Messages, m.ReferencedMessage.ID)
|
||||
app.MessagesTextView.
|
||||
Highlight(m.ReferencedMessage.ID).
|
||||
ScrollToHighlight()
|
||||
messageActionsList.AddItem("Select Reply", "", 'r', nil)
|
||||
}
|
||||
|
||||
return nil
|
||||
} else if util.HasKeybinding(app.Config.Keybindings.ReplySelectedMessage, e.Name()) {
|
||||
hs := app.MessagesTextView.GetHighlights()
|
||||
if len(hs) == 0 {
|
||||
return nil
|
||||
}
|
||||
messageActionsList.
|
||||
ShowSecondaryText(false).
|
||||
AddItem("Copy Content", "", 'c', nil).
|
||||
AddItem("Copy ID", "", 'i', nil).
|
||||
SetDoneFunc(func() {
|
||||
app.SetRoot(app.MainFlex, true)
|
||||
}).
|
||||
SetSelectedFunc(func(_ int, mainText string, _ string, _ rune) {
|
||||
onMessageActionsListSelected(app, mainText, m)
|
||||
}).
|
||||
SetTitle("Press the Escape key to close").
|
||||
SetBorder(true)
|
||||
|
||||
_, m := util.FindMessageByID(app.SelectedChannel.Messages, hs[0])
|
||||
app.MessageInputField.SetTitle("Replying to " + m.Author.String())
|
||||
app.SetFocus(app.MessageInputField)
|
||||
return nil
|
||||
} else if util.HasKeybinding(app.Config.Keybindings.MentionReplySelectedMessage, e.Name()) {
|
||||
hs := app.MessagesTextView.GetHighlights()
|
||||
if len(hs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, m := util.FindMessageByID(app.SelectedChannel.Messages, hs[0])
|
||||
app.MessageInputField.SetTitle("[@] Replying to " + m.Author.String())
|
||||
app.SetFocus(app.MessageInputField)
|
||||
return nil
|
||||
} else if util.HasKeybinding(app.Config.Keybindings.CopySelectedMessage, e.Name()) {
|
||||
hs := app.MessagesTextView.GetHighlights()
|
||||
if len(hs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, m := util.FindMessageByID(app.SelectedChannel.Messages, hs[0])
|
||||
err := clipboard.WriteAll(m.Content)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
app.SetRoot(messageActionsList, true)
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func onMessageActionsListSelected(app *App, mainText string, m *discordgo.Message) {
|
||||
switch mainText {
|
||||
case "Copy Content":
|
||||
if err := clipboard.WriteAll(m.Content); err != nil {
|
||||
return
|
||||
}
|
||||
case "Copy ID":
|
||||
if err := clipboard.WriteAll(m.ID); err != nil {
|
||||
return
|
||||
}
|
||||
case "Reply":
|
||||
app.SetFocus(app.MessageInputField)
|
||||
app.MessageInputField.SetTitle("Replying to " + m.Author.String())
|
||||
case "Mention Reply":
|
||||
app.SetFocus(app.MessageInputField)
|
||||
app.MessageInputField.SetTitle("[@] Replying to " + m.Author.String())
|
||||
case "Select Reply":
|
||||
app.SelectedMessage, _ = util.FindMessageByID(app.SelectedChannel.Messages, m.ReferencedMessage.ID)
|
||||
app.MessagesTextView.
|
||||
Highlight(m.ReferencedMessage.ID).
|
||||
ScrollToHighlight()
|
||||
}
|
||||
|
||||
app.SetRoot(app.MainFlex, true)
|
||||
}
|
||||
|
||||
func onMessageInputFieldInputCapture(app *App, e *tcell.EventKey) *tcell.EventKey {
|
||||
// The default global navigation shortcut for guilds list is Alt+<rune>.
|
||||
if e.Modifiers() == tcell.ModAlt {
|
||||
|
|
|
|||
|
|
@ -63,9 +63,11 @@ func NewMainFlex(app *App) *tview.Flex {
|
|||
AddItem(app.MessagesTextView, 0, 1, false).
|
||||
AddItem(app.MessageInputField, 3, 1, false)
|
||||
|
||||
return tview.NewFlex().
|
||||
app.MainFlex = tview.NewFlex().
|
||||
AddItem(leftFlex, 0, 1, false).
|
||||
AddItem(rightFlex, 0, 4, false)
|
||||
|
||||
return app.MainFlex
|
||||
}
|
||||
|
||||
func NewLoginForm(mfa bool) *tview.Form {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue