aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-04-26 10:28:41 +0200
committerGitHub <noreply@github.com>2022-04-26 10:28:41 +0200
commitfeac9db43fc459f1efa10424dfc96f8d54b55c64 (patch)
tree7773dd81cdc38d77c34bd856a05210cc0df9e356 /clientapi
parent7df5d69a5b606e226c5d83c23aa9dd90785c0b2d (diff)
Add transactionsCache to redact endpoint (#2375)
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/routing/redaction.go20
-rw-r--r--clientapi/routing/routing.go5
2 files changed, 22 insertions, 3 deletions
diff --git a/clientapi/routing/redaction.go b/clientapi/routing/redaction.go
index 01ea818a..e8d14ce3 100644
--- a/clientapi/routing/redaction.go
+++ b/clientapi/routing/redaction.go
@@ -22,6 +22,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/httputil"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/internal/eventutil"
+ "github.com/matrix-org/dendrite/internal/transactions"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api"
@@ -40,12 +41,21 @@ type redactionResponse struct {
func SendRedaction(
req *http.Request, device *userapi.Device, roomID, eventID string, cfg *config.ClientAPI,
rsAPI roomserverAPI.RoomserverInternalAPI,
+ txnID *string,
+ txnCache *transactions.Cache,
) util.JSONResponse {
resErr := checkMemberInRoom(req.Context(), rsAPI, device.UserID, roomID)
if resErr != nil {
return *resErr
}
+ if txnID != nil {
+ // Try to fetch response from transactionsCache
+ if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok {
+ return *res
+ }
+ }
+
ev := roomserverAPI.GetEvent(req.Context(), rsAPI, eventID)
if ev == nil {
return util.JSONResponse{
@@ -124,10 +134,18 @@ func SendRedaction(
util.GetLogger(req.Context()).WithError(err).Errorf("failed to SendEvents")
return jsonerror.InternalServerError()
}
- return util.JSONResponse{
+
+ res := util.JSONResponse{
Code: 200,
JSON: redactionResponse{
EventID: e.EventID(),
},
}
+
+ // Add response to transactionsCache
+ if txnID != nil {
+ txnCache.AddTransaction(device.AccessToken, *txnID, &res)
+ }
+
+ return res
}
diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go
index 37d825b8..f370b4f8 100644
--- a/clientapi/routing/routing.go
+++ b/clientapi/routing/routing.go
@@ -479,7 +479,7 @@ func Setup(
if err != nil {
return util.ErrorResponse(err)
}
- return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
+ return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, nil, nil)
}),
).Methods(http.MethodPost, http.MethodOptions)
v3mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
@@ -488,7 +488,8 @@ func Setup(
if err != nil {
return util.ErrorResponse(err)
}
- return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
+ txnID := vars["txnId"]
+ return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, &txnID, transactionsCache)
}),
).Methods(http.MethodPut, http.MethodOptions)