From c829e436e46ace700045eaaf31bc4abf286e1156 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 1 Mar 2020 22:35:21 +0200 Subject: Implement sending redactions --- ui/commands.go | 5 +---- ui/room-view.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'ui') 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) -- cgit v1.2.3