mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Implement forgetting about rooms (#1572)
* Add basic storage methods * Add internal api handler * Add check for forgotten room * Add /rooms/{roomID}/forget endpoint * Add missing rsAPI method * Remove unused parameters * Add passing tests Signed-off-by: Till Faelligen <tfaelligen@gmail.com> * Add missing file * Add postgres migration * Add sqlite migration * Use Forgetter to forget room * Remove empty line * Update HTTP status codes It looks like the spec calls for these to be 400, rather than 403: https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-rooms-roomid-forget Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
This commit is contained in:
parent
2ce2112ddb
commit
eccd0d2c1b
25 changed files with 543 additions and 136 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue