Distinguish between room not existing and room being abandoned on this server

This commit is contained in:
Neil Alexander 2020-09-24 15:33:17 +01:00
parent e846ae0e5d
commit 1c6bd5fa80
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 11 additions and 2 deletions

View file

@ -89,10 +89,16 @@ func MakeJoin(
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed") util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
if !inRoomRes.RoomExists {
return util.JSONResponse{
Code: http.StatusNotFound,
JSON: jsonerror.NotFound(fmt.Sprintf("Room ID %q was not found on this server", roomID)),
}
}
if !inRoomRes.IsInRoom { if !inRoomRes.IsInRoom {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,
JSON: jsonerror.NotFound("There are no remaining users in this room"), JSON: jsonerror.NotFound(fmt.Sprintf("Room ID %q has no remaining users on this server", roomID)),
} }
} }

View file

@ -150,6 +150,8 @@ type QueryServerJoinedToRoomRequest struct {
// QueryMembershipsForRoomResponse is a response to QueryServerJoinedToRoom // QueryMembershipsForRoomResponse is a response to QueryServerJoinedToRoom
type QueryServerJoinedToRoomResponse struct { type QueryServerJoinedToRoomResponse struct {
// True if the room exists on the server
RoomExists bool `json:"room_exists"`
// True if we still believe that we are participating in the room // True if we still believe that we are participating in the room
IsInRoom bool `json:"is_in_room"` IsInRoom bool `json:"is_in_room"`
} }

View file

@ -237,9 +237,10 @@ func (r *Queryer) QueryServerJoinedToRoom(
if err != nil { if err != nil {
return fmt.Errorf("r.DB.RoomInfo: %w", err) return fmt.Errorf("r.DB.RoomInfo: %w", err)
} }
if info == nil { if info == nil || info.IsStub {
return nil return nil
} }
response.RoomExists = true
eventNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, true, false) eventNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, true, false)
if err != nil { if err != nil {