From 1c6bd5fa800b1daaa0c02757d5e92dcd0ff33451 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 24 Sep 2020 15:33:17 +0100 Subject: [PATCH] Distinguish between room not existing and room being abandoned on this server --- federationapi/routing/join.go | 8 +++++++- roomserver/api/query.go | 2 ++ roomserver/internal/query/query.go | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index ef03f7a74..68cf86193 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -89,10 +89,16 @@ func MakeJoin( util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryServerJoinedToRoom failed") 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 { return util.JSONResponse{ 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)), } } diff --git a/roomserver/api/query.go b/roomserver/api/query.go index 4b784a21f..5d61e862c 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -150,6 +150,8 @@ type QueryServerJoinedToRoomRequest struct { // QueryMembershipsForRoomResponse is a response to QueryServerJoinedToRoom 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 IsInRoom bool `json:"is_in_room"` } diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index ec89df749..58cb44933 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -237,9 +237,10 @@ func (r *Queryer) QueryServerJoinedToRoom( if err != nil { return fmt.Errorf("r.DB.RoomInfo: %w", err) } - if info == nil { + if info == nil || info.IsStub { return nil } + response.RoomExists = true eventNIDs, err := r.DB.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, true, false) if err != nil {