From 9d132d328bbf3cdcb66d34538583a96268b6dd09 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 1 Mar 2020 00:33:37 +0200 Subject: Add support for replying and reacting to messages --- ui/commands.go | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'ui/commands.go') diff --git a/ui/commands.go b/ui/commands.go index 0f07e94..c7f0301 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -41,7 +41,6 @@ import ( func cmdMe(cmd *Command) { text := strings.Join(cmd.Args, " ") go cmd.Room.SendMessage(mautrix.MsgEmote, text) - cmd.UI.Render() } // GradientTable from https://github.com/lucasb-eyer/go-colorful/blob/master/doc/gradientgen/gradientgen.go @@ -87,10 +86,9 @@ func makeRainbow(cmd *Command, msgtype mautrix.MessageType) { continue } color := rainbow.GetInterpolatedColorFor(float64(i) / float64(len(text))).Hex() - _, _ = fmt.Fprintf(&html, "%c", color, char) + _, _ = fmt.Fprintf(&html, "%[2]c", color, char) } go cmd.Room.SendMessage(msgtype, html.String()) - cmd.UI.Render() } func cmdRainbow(cmd *Command) { @@ -103,7 +101,6 @@ func cmdRainbowMe(cmd *Command) { func cmdNotice(cmd *Command) { go cmd.Room.SendMessage(mautrix.MsgNotice, strings.Join(cmd.Args, " ")) - cmd.UI.Render() } func cmdAccept(cmd *Command) { @@ -141,6 +138,42 @@ func cmdID(cmd *Command) { cmd.Reply("The internal ID of this room is %s", cmd.Room.MxRoom().ID) } +type SelectReason string + +const ( + SelectReply SelectReason = "reply to" + SelectReact = "react to" + SelectRedact = "redact" +) + +func cmdReply(cmd *Command) { + cmd.Room.selecting = true + cmd.Room.selectReason = SelectReply + cmd.Room.selectContent = strings.Join(cmd.Args, " ") + cmd.Room.OnSelect(cmd.Room.MessageView().selected) +} + +func cmdRedact(cmd *Command) { + cmd.Reply("Not yet implemented 3:") + + // This needs to be implemented in RoomView's OnSelect method + //cmd.Room.selecting = true + //cmd.Room.selectReason = SelectRedact + //cmd.Room.OnSelect(cmd.Room.MessageView().selected) +} + +func cmdReact(cmd *Command) { + if len(cmd.Args) == 0 { + cmd.Reply("Usage: /react ") + return + } + + cmd.Room.selecting = true + cmd.Room.selectReason = SelectReact + cmd.Room.selectContent = strings.Join(cmd.Args, " ") + cmd.Room.OnSelect(cmd.Room.MessageView().selected) +} + func cmdTags(cmd *Command) { tags := cmd.Room.MxRoom().RawTags if len(cmd.Args) > 0 && cmd.Args[0] == "--internal" { @@ -298,6 +331,9 @@ Things: rooms, users, baremessages, images, typingnotif /notice - Send a notice (generally used for bot messages). /rainbow - Send rainbow text (markdown not supported). /rainbowme - Send rainbow text in an emote. +/reply [text] - Reply to the selected message. +/react - React to the selected message. +/redact - Redact the selected message. # Rooms /pm <...> - Create a private chat with the given user(s). -- cgit v1.2.3