From 23afb2ecef71f15a9c777e28ebdbe38c128be0b2 Mon Sep 17 00:00:00 2001 From: rigormorrtiss Date: Tue, 31 Aug 2021 15:56:03 +0400 Subject: [PATCH] feat: implement reply to selected message functionality (#39) * feat: implement reply to selected message functionality * docs: add keybinding for reply --- README.md | 1 + discordo.go | 23 ++++++++++++++++++++++- ui/inputfields.go | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71a50b2..773ded7 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ TextView: - `j` or `Down`: Selects the message just after the currently selected message. - `g` or `Home`: Selects the first message rendered in the TextView. - `G` or `End`: Selects the last message rendered in the TextView. +- `r`: Reply to the selected message. ### Clipboard diff --git a/discordo.go b/discordo.go index 947ef51..a6cb43e 100644 --- a/discordo.go +++ b/discordo.go @@ -24,6 +24,7 @@ var ( config *util.Config session *discordgo.Session selectedChannel *discordgo.Channel + selectedMessage *discordgo.Message ) func main() { @@ -174,6 +175,21 @@ func onMessagesTextViewInputCapture(e *tcell.EventKey) *tcell.EventKey { messagesTextView. Highlight(ms[0].ID). ScrollToHighlight() + case e.Rune() == 'r': // Reply + hs := messagesTextView.GetHighlights() + if len(hs) == 0 { + return nil + } + + for _, m := range selectedChannel.Messages { + if m.ID == hs[0] { + selectedMessage = m + break + } + } + + messageInputField.SetTitle("Replying to " + selectedMessage.Author.Username) + app.SetFocus(messageInputField) } return e @@ -191,8 +207,13 @@ func onMessageInputFieldInputCapture(e *tcell.EventKey) *tcell.EventKey { return nil } + if selectedMessage != nil { + go session.ChannelMessageSendReply(selectedMessage.ChannelID, t, selectedMessage.Reference()) + } else { + go session.ChannelMessageSend(selectedChannel.ID, t) + } + messageInputField.SetText("") - go session.ChannelMessageSend(selectedChannel.ID, t) case tcell.KeyCtrlV: text, _ := clipboard.ReadAll() text = messageInputField.GetText() + text diff --git a/ui/inputfields.go b/ui/inputfields.go index 77c39e5..9f186c2 100644 --- a/ui/inputfields.go +++ b/ui/inputfields.go @@ -16,7 +16,8 @@ func NewMessageInputField( SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor). SetInputCapture(onMessageInputFieldInputCapture). SetBorder(true). - SetBorderPadding(0, 0, 1, 0) + SetBorderPadding(0, 0, 1, 0). + SetTitleAlign(tview.AlignLeft) return i }