diff options
author | Tulir Asokan <tulir@maunium.net> | 2020-03-01 22:35:21 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2020-03-01 22:35:25 +0200 |
commit | c829e436e46ace700045eaaf31bc4abf286e1156 (patch) | |
tree | 17fc5584554352279419759d273d283a130e3579 | |
parent | 5ea77a6c5f1ad351cdc0159181cc45ae3b1f3d1a (diff) |
Implement sending redactions
-rw-r--r-- | interface/matrix.go | 1 | ||||
-rw-r--r-- | matrix/matrix.go | 8 | ||||
-rw-r--r-- | ui/commands.go | 5 | ||||
-rw-r--r-- | ui/room-view.go | 17 |
4 files changed, 25 insertions, 6 deletions
diff --git a/interface/matrix.go b/interface/matrix.go index 34e8dda..6814f07 100644 --- a/interface/matrix.go +++ b/interface/matrix.go @@ -42,6 +42,7 @@ type MatrixContainer interface { SendPreferencesToMatrix() PrepareMarkdownMessage(roomID string, msgtype mautrix.MessageType, message string, relation *Relation) *event.Event SendEvent(evt *event.Event) (string, error) + Redact(roomID, eventID, reason string) error SendTyping(roomID string, typing bool) MarkRead(roomID, eventID string) JoinRoom(roomID, server string) (*rooms.Room, error) diff --git a/matrix/matrix.go b/matrix/matrix.go index 8cf2e96..4408ac5 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -768,7 +768,13 @@ func (c *Container) PrepareMarkdownMessage(roomID string, msgtype mautrix.Messag return localEcho } -// SendMarkdownMessage sends a message with the given markdown text to the given room. +func (c *Container) Redact(roomID, eventID, reason string) error { + defer debug.Recover() + _, err := c.client.RedactEvent(roomID, eventID, mautrix.ReqRedact{Reason: reason}) + return err +} + +// SendMessage sends the given event. func (c *Container) SendEvent(event *event.Event) (string, error) { defer debug.Recover() diff --git a/ui/commands.go b/ui/commands.go index 9ef0577..879aca7 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -151,10 +151,7 @@ func cmdReply(cmd *Command) { } func cmdRedact(cmd *Command) { - cmd.Reply("Not yet implemented 3:") - - // This needs to be implemented in RoomView's OnSelect method - //cmd.Room.StartSelecting(SelectRedact, "") + cmd.Room.StartSelecting(SelectRedact, strings.Join(cmd.Args, " ")) } func cmdReact(cmd *Command) { diff --git a/ui/room-view.go b/ui/room-view.go index 0e728a3..11b4508 100644 --- a/ui/room-view.go +++ b/ui/room-view.go @@ -190,7 +190,7 @@ func (view *RoomView) OnSelect(message *messages.UIMessage) { case SelectReact: go view.SendReaction(message.EventID, view.selectContent) case SelectRedact: - // TODO redact + go view.Redact(message.EventID, view.selectContent) } view.selecting = false view.selectContent = "" @@ -580,6 +580,21 @@ func (view *RoomView) InputSubmit(text string) { view.SetInputText("") } +func (view *RoomView) Redact(eventID, reason string) { + defer debug.Recover() + err := view.parent.matrix.Redact(view.Room.ID, eventID, reason) + if err != nil { + if httpErr, ok := err.(mautrix.HTTPError); ok { + err = httpErr + if respErr := httpErr.RespError; respErr != nil { + err = respErr + } + } + view.AddServiceMessage(fmt.Sprintf("Failed to redact message: %v", err)) + view.parent.parent.Render() + } +} + func (view *RoomView) SendReaction(eventID string, reaction string) { defer debug.Recover() debug.Print("Reacting to", eventID, "in", view.Room.ID, "with", reaction) |