feat: implement reply to selected message functionality (#39)

* feat: implement reply to selected message functionality

* docs: add keybinding for reply
This commit is contained in:
rigormorrtiss 2021-08-31 15:56:03 +04:00 • committed by GitHub
parent 5d19c768fe
commit 23afb2ecef
3 changed files with 25 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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
}