mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -06:00
Implement POST version of /redact
Signed-off-by: Alex Chen <minecnly@gmail.com>
This commit is contained in:
parent
bc4a3be298
commit
632b88252f
|
|
@ -41,10 +41,11 @@ type redactResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redact implements PUT /_matrix/client/r0/rooms/{roomId}/redact/{eventId}/{txnId}
|
// 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(
|
func Redact(
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
device *authtypes.Device,
|
device *authtypes.Device,
|
||||||
roomID, redactedEventID, txnID string,
|
roomID, redactedEventID string, txnID *string,
|
||||||
cfg config.Dendrite,
|
cfg config.Dendrite,
|
||||||
queryAPI api.RoomserverQueryAPI,
|
queryAPI api.RoomserverQueryAPI,
|
||||||
producer *producers.RoomserverProducer,
|
producer *producers.RoomserverProducer,
|
||||||
|
|
@ -127,15 +128,18 @@ func Redact(
|
||||||
|
|
||||||
// Send the redaction event
|
// Send the redaction event
|
||||||
|
|
||||||
txnAndDeviceID := api.TransactionID{
|
var txnAndDeviceID *api.TransactionID
|
||||||
TransactionID: txnID,
|
if txnID != nil {
|
||||||
DeviceID: device.ID,
|
txnAndDeviceID = &api.TransactionID{
|
||||||
|
TransactionID: *txnID,
|
||||||
|
DeviceID: device.ID,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass the new event to the roomserver and receive the correct event ID
|
// pass the new event to the roomserver and receive the correct event ID
|
||||||
// event ID in case of duplicate transaction is discarded
|
// event ID in case of duplicate transaction is discarded
|
||||||
eventID, err := producer.SendEvents(
|
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 {
|
if err != nil {
|
||||||
return httputil.LogThenError(req, err)
|
return httputil.LogThenError(req, err)
|
||||||
|
|
|
||||||
|
|
@ -164,10 +164,21 @@ func Setup(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.ErrorResponse(err)
|
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)
|
cfg, queryAPI, producer, transactionsCache)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodPut, http.MethodOptions)
|
).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 {
|
r0mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
||||||
return Register(req, accountDB, deviceDB, &cfg)
|
return Register(req, accountDB, deviceDB, &cfg)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue