mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 03:13: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}
|
||||
// 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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue