aboutsummaryrefslogtreecommitdiff
path: root/syncapi/routing
diff options
context:
space:
mode:
Diffstat (limited to 'syncapi/routing')
-rw-r--r--syncapi/routing/messages.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go
index e5299f20..2f79ed5c 100644
--- a/syncapi/routing/messages.go
+++ b/syncapi/routing/messages.go
@@ -59,6 +59,7 @@ const defaultMessagesLimit = 10
// OnIncomingMessagesRequest implements the /messages endpoint from the
// client-server API.
// See: https://matrix.org/docs/spec/client_server/latest.html#get-matrix-client-r0-rooms-roomid-messages
+// nolint:gocyclo
func OnIncomingMessagesRequest(
req *http.Request, db storage.Database, roomID string, device *userapi.Device,
federation *gomatrixserverlib.FederationClient,
@@ -67,6 +68,19 @@ func OnIncomingMessagesRequest(
) util.JSONResponse {
var err error
+ // check if the user has already forgotten about this room
+ isForgotten, err := checkIsRoomForgotten(req.Context(), roomID, device.UserID, rsAPI)
+ if err != nil {
+ return jsonerror.InternalServerError()
+ }
+
+ if isForgotten {
+ return util.JSONResponse{
+ Code: http.StatusForbidden,
+ JSON: jsonerror.Forbidden("user already forgot about this room"),
+ }
+ }
+
// Extract parameters from the request's URL.
// Pagination tokens.
var fromStream *types.StreamingToken
@@ -182,6 +196,19 @@ func OnIncomingMessagesRequest(
}
}
+func checkIsRoomForgotten(ctx context.Context, roomID, userID string, rsAPI api.RoomserverInternalAPI) (bool, error) {
+ req := api.QueryMembershipForUserRequest{
+ RoomID: roomID,
+ UserID: userID,
+ }
+ resp := api.QueryMembershipForUserResponse{}
+ if err := rsAPI.QueryMembershipForUser(ctx, &req, &resp); err != nil {
+ return false, err
+ }
+
+ return resp.IsRoomForgotten, nil
+}
+
// retrieveEvents retrieves events from the local database for a request on
// /messages. If there's not enough events to retrieve, it asks another
// homeserver in the room for older events.