diff --git a/clientapi/routing/redact.go b/clientapi/routing/redact.go index 45ab60b43..15b8f430b 100644 --- a/clientapi/routing/redact.go +++ b/clientapi/routing/redact.go @@ -41,10 +41,11 @@ type redactResponse struct { } // Redact implements PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId} +// and POST /_matrix/client/r0/rooms/{roomId}/redact/{eventId} (mainly for SyTest) func Redact( req *http.Request, device *authtypes.Device, - roomID, redactedEventID, txnID string, + roomID, redactedEventID string, txnID *string, cfg config.Dendrite, queryAPI api.RoomserverQueryAPI, producer *producers.RoomserverProducer, @@ -127,15 +128,18 @@ func Redact( // Send the redaction event - txnAndDeviceID := api.TransactionID{ - TransactionID: txnID, - DeviceID: device.ID, + var txnAndDeviceID *api.TransactionID + if txnID != nil { + txnAndDeviceID = &api.TransactionID{ + TransactionID: *txnID, + DeviceID: device.ID, + } } // pass the new event to the roomserver and receive the correct event ID // event ID in case of duplicate transaction is discarded eventID, err := producer.SendEvents( - req.Context(), []gomatrixserverlib.Event{*e}, cfg.Matrix.ServerName, &txnAndDeviceID, + req.Context(), []gomatrixserverlib.Event{*e}, cfg.Matrix.ServerName, txnAndDeviceID, ) if err != nil { return httputil.LogThenError(req, err) diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 5e0cc3058..9198b8a3a 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -164,10 +164,21 @@ func Setup( if err != nil { return util.ErrorResponse(err) } - return Redact(req, device, vars["roomID"], vars["eventID"], vars["txnID"], + txnID := vars["txnID"] + return Redact(req, device, vars["roomID"], vars["eventID"], &txnID, cfg, queryAPI, producer, transactionsCache) }), ).Methods(http.MethodPut, http.MethodOptions) + r0mux.Handle("/rooms/{roomID}/redact/{eventID}", + common.MakeAuthAPI("redact", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars, err := common.URLDecodeMapValues(mux.Vars(req)) + if err != nil { + return util.ErrorResponse(err) + } + return Redact(req, device, vars["roomID"], vars["eventID"], nil, + cfg, queryAPI, producer, transactionsCache) + }), + ).Methods(http.MethodPost, http.MethodOptions) r0mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { return Register(req, accountDB, deviceDB, &cfg)