From fa533521abc9ca8a5f49ef1c6a44e4de38c5110e Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Wed, 15 Dec 2021 10:23:43 -0700 Subject: [PATCH 1/2] client.RedactEvent: allow arbitrary fields in redaction request --- client.go | 3 ++- requests.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 66ef79b6..37afbfc4 100644 --- a/client.go +++ b/client.go @@ -974,6 +974,7 @@ func (cli *Client) RedactEvent(roomID id.RoomID, eventID id.EventID, extra ...Re req := ReqRedact{} if len(extra) > 0 { req = extra[0] + req.Extra["reason"] = req.Reason } var txnID string if len(req.TxnID) > 0 { @@ -982,7 +983,7 @@ func (cli *Client) RedactEvent(roomID id.RoomID, eventID id.EventID, extra ...Re txnID = cli.TxnID() } urlPath := cli.BuildURL("rooms", roomID, "redact", eventID, txnID) - _, err = cli.MakeRequest("PUT", urlPath, req, &resp) + _, err = cli.MakeRequest("PUT", urlPath, req.Extra, &resp) return } diff --git a/requests.go b/requests.go index f325616d..41b2de90 100644 --- a/requests.go +++ b/requests.go @@ -105,8 +105,9 @@ type ReqCreateRoom struct { // ReqRedact is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-redact-eventid-txnid type ReqRedact struct { - Reason string `json:"reason,omitempty"` - TxnID string `json:"-"` + Reason string + TxnID string + Extra map[string]interface{} } type ReqMembers struct { From 0679a0ba703d14d828e86d142e3714a1488e2e85 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 15 Dec 2021 19:29:05 +0200 Subject: [PATCH 2/2] Ensure redact request body is always set --- client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client.go b/client.go index 37afbfc4..64965590 100644 --- a/client.go +++ b/client.go @@ -974,6 +974,11 @@ func (cli *Client) RedactEvent(roomID id.RoomID, eventID id.EventID, extra ...Re req := ReqRedact{} if len(extra) > 0 { req = extra[0] + } + if req.Extra == nil { + req.Extra = make(map[string]interface{}) + } + if len(req.Reason) > 0 { req.Extra["reason"] = req.Reason } var txnID string