Explorar o código

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

* feat: implement reply to selected message functionality

* docs: add keybinding for reply
rigormorrtiss %!s(int64=4) %!d(string=hai) anos
pai
achega
23afb2ecef
Modificáronse 3 ficheiros con 25 adicións e 2 borrados
  1. 1 0
      README.md
  2. 22 1
      discordo.go
  3. 2 1
      ui/inputfields.go

+ 1 - 0
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
 

+ 22 - 1
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

+ 2 - 1
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
 }