mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Add RoomExists flag to QueryMembershipForUser (#2450)
Fixes https://github.com/matrix-org/complement/pull/369
This commit is contained in:
parent
6db08b2874
commit
c15bfefd0d
6 changed files with 38 additions and 5 deletions
|
@ -73,6 +73,12 @@ func Context(
|
|||
logrus.WithError(err).Error("unable to query membership")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
if !membershipRes.RoomExists {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusForbidden,
|
||||
JSON: jsonerror.Forbidden("room does not exist"),
|
||||
}
|
||||
}
|
||||
|
||||
stateFilter := gomatrixserverlib.StateFilter{
|
||||
Limit: 100,
|
||||
|
|
|
@ -68,10 +68,16 @@ func OnIncomingMessagesRequest(
|
|||
var err error
|
||||
|
||||
// check if the user has already forgotten about this room
|
||||
isForgotten, err := checkIsRoomForgotten(req.Context(), roomID, device.UserID, rsAPI)
|
||||
isForgotten, roomExists, err := checkIsRoomForgotten(req.Context(), roomID, device.UserID, rsAPI)
|
||||
if err != nil {
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
if !roomExists {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusForbidden,
|
||||
JSON: jsonerror.Forbidden("room does not exist"),
|
||||
}
|
||||
}
|
||||
|
||||
if isForgotten {
|
||||
return util.JSONResponse{
|
||||
|
@ -244,17 +250,17 @@ func OnIncomingMessagesRequest(
|
|||
}
|
||||
}
|
||||
|
||||
func checkIsRoomForgotten(ctx context.Context, roomID, userID string, rsAPI api.SyncRoomserverAPI) (bool, error) {
|
||||
func checkIsRoomForgotten(ctx context.Context, roomID, userID string, rsAPI api.SyncRoomserverAPI) (forgotten bool, exists bool, err error) {
|
||||
req := api.QueryMembershipForUserRequest{
|
||||
RoomID: roomID,
|
||||
UserID: userID,
|
||||
}
|
||||
resp := api.QueryMembershipForUserResponse{}
|
||||
if err := rsAPI.QueryMembershipForUser(ctx, &req, &resp); err != nil {
|
||||
return false, err
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
return resp.IsRoomForgotten, nil
|
||||
return resp.IsRoomForgotten, resp.RoomExists, nil
|
||||
}
|
||||
|
||||
// retrieveEvents retrieves events from the local database for a request on
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue