From 67cc8619d3c655beb91387cd82ecccd50b0d8f48 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Fri, 4 Sep 2020 11:46:01 +0100 Subject: [PATCH] Remove QueryKnownUsers from current state server (#1393) * Remove QueryKnownUsers from current state server * Fix HTTP mode --- clientapi/routing/routing.go | 2 +- clientapi/routing/userdirectory.go | 12 ++++++------ currentstateserver/api/api.go | 13 ------------- currentstateserver/internal/api.go | 14 -------------- currentstateserver/inthttp/client.go | 10 ---------- currentstateserver/inthttp/server.go | 13 ------------- roomserver/inthttp/server.go | 2 +- syncapi/internal/keychange_test.go | 4 ---- 8 files changed, 8 insertions(+), 62 deletions(-) diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 0c63f968..14acc42f 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -639,7 +639,7 @@ func Setup( req.Context(), device, userAPI, - stateAPI, + rsAPI, cfg.Matrix.ServerName, postContent.SearchString, postContent.Limit, diff --git a/clientapi/routing/userdirectory.go b/clientapi/routing/userdirectory.go index db81ffea..2659bc9c 100644 --- a/clientapi/routing/userdirectory.go +++ b/clientapi/routing/userdirectory.go @@ -19,7 +19,7 @@ import ( "fmt" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - currentstateAPI "github.com/matrix-org/dendrite/currentstateserver/api" + "github.com/matrix-org/dendrite/roomserver/api" userapi "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -34,7 +34,7 @@ func SearchUserDirectory( ctx context.Context, device *userapi.Device, userAPI userapi.UserInternalAPI, - stateAPI currentstateAPI.CurrentStateInternalAPI, + rsAPI api.RoomserverInternalAPI, serverName gomatrixserverlib.ServerName, searchString string, limit int, @@ -81,14 +81,14 @@ func SearchUserDirectory( // start searching for known users from joined rooms. if len(results) <= limit { - stateReq := ¤tstateAPI.QueryKnownUsersRequest{ + stateReq := &api.QueryKnownUsersRequest{ UserID: device.UserID, SearchString: searchString, Limit: limit - len(results), } - stateRes := ¤tstateAPI.QueryKnownUsersResponse{} - if err := stateAPI.QueryKnownUsers(ctx, stateReq, stateRes); err != nil { - errRes := util.ErrorResponse(fmt.Errorf("stateAPI.QueryKnownUsers: %w", err)) + stateRes := &api.QueryKnownUsersResponse{} + if err := rsAPI.QueryKnownUsers(ctx, stateReq, stateRes); err != nil { + errRes := util.ErrorResponse(fmt.Errorf("rsAPI.QueryKnownUsers: %w", err)) return &errRes } diff --git a/currentstateserver/api/api.go b/currentstateserver/api/api.go index 4ebe2968..b778acb2 100644 --- a/currentstateserver/api/api.go +++ b/currentstateserver/api/api.go @@ -20,7 +20,6 @@ import ( "fmt" "strings" - "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/gomatrixserverlib" ) @@ -34,8 +33,6 @@ type CurrentStateInternalAPI interface { QueryBulkStateContent(ctx context.Context, req *QueryBulkStateContentRequest, res *QueryBulkStateContentResponse) error // QuerySharedUsers returns a list of users who share at least 1 room in common with the given user. QuerySharedUsers(ctx context.Context, req *QuerySharedUsersRequest, res *QuerySharedUsersResponse) error - // QueryKnownUsers returns a list of users that we know about from our joined rooms. - QueryKnownUsers(ctx context.Context, req *QueryKnownUsersRequest, res *QueryKnownUsersResponse) error } type QuerySharedUsersRequest struct { @@ -91,16 +88,6 @@ type QueryCurrentStateResponse struct { StateEvents map[gomatrixserverlib.StateKeyTuple]*gomatrixserverlib.HeaderedEvent } -type QueryKnownUsersRequest struct { - UserID string `json:"user_id"` - SearchString string `json:"search_string"` - Limit int `json:"limit"` -} - -type QueryKnownUsersResponse struct { - Users []authtypes.FullyQualifiedProfile `json:"profiles"` -} - // MarshalJSON stringifies the StateKeyTuple keys so they can be sent over the wire in HTTP API mode. func (r *QueryCurrentStateResponse) MarshalJSON() ([]byte, error) { se := make(map[string]*gomatrixserverlib.HeaderedEvent, len(r.StateEvents)) diff --git a/currentstateserver/internal/api.go b/currentstateserver/internal/api.go index dc255412..c581c524 100644 --- a/currentstateserver/internal/api.go +++ b/currentstateserver/internal/api.go @@ -17,7 +17,6 @@ package internal import ( "context" - "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/currentstateserver/api" "github.com/matrix-org/dendrite/currentstateserver/storage" "github.com/matrix-org/gomatrixserverlib" @@ -50,19 +49,6 @@ func (a *CurrentStateInternalAPI) QueryRoomsForUser(ctx context.Context, req *ap return nil } -func (a *CurrentStateInternalAPI) QueryKnownUsers(ctx context.Context, req *api.QueryKnownUsersRequest, res *api.QueryKnownUsersResponse) error { - users, err := a.DB.GetKnownUsers(ctx, req.UserID, req.SearchString, req.Limit) - if err != nil { - return err - } - for _, user := range users { - res.Users = append(res.Users, authtypes.FullyQualifiedProfile{ - UserID: user, - }) - } - return nil -} - func (a *CurrentStateInternalAPI) QueryBulkStateContent(ctx context.Context, req *api.QueryBulkStateContentRequest, res *api.QueryBulkStateContentResponse) error { events, err := a.DB.GetBulkStateContent(ctx, req.RoomIDs, req.StateTuples, req.AllowWildcards) if err != nil { diff --git a/currentstateserver/inthttp/client.go b/currentstateserver/inthttp/client.go index 37d289ea..18151f63 100644 --- a/currentstateserver/inthttp/client.go +++ b/currentstateserver/inthttp/client.go @@ -98,13 +98,3 @@ func (h *httpCurrentStateInternalAPI) QuerySharedUsers( apiURL := h.apiURL + QuerySharedUsersPath return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) } - -func (h *httpCurrentStateInternalAPI) QueryKnownUsers( - ctx context.Context, req *api.QueryKnownUsersRequest, res *api.QueryKnownUsersResponse, -) error { - span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKnownUsers") - defer span.Finish() - - apiURL := h.apiURL + QueryKnownUsersPath - return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) -} diff --git a/currentstateserver/inthttp/server.go b/currentstateserver/inthttp/server.go index aee900e0..f4e93dcd 100644 --- a/currentstateserver/inthttp/server.go +++ b/currentstateserver/inthttp/server.go @@ -77,17 +77,4 @@ func AddRoutes(internalAPIMux *mux.Router, intAPI api.CurrentStateInternalAPI) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - internalAPIMux.Handle(QuerySharedUsersPath, - httputil.MakeInternalAPI("queryKnownUsers", func(req *http.Request) util.JSONResponse { - request := api.QueryKnownUsersRequest{} - response := api.QueryKnownUsersResponse{} - if err := json.NewDecoder(req.Body).Decode(&request); err != nil { - return util.MessageResponse(http.StatusBadRequest, err.Error()) - } - if err := intAPI.QueryKnownUsers(req.Context(), &request, &response); err != nil { - return util.ErrorResponse(err) - } - return util.JSONResponse{Code: http.StatusOK, JSON: &response} - }), - ) } diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go index ebfb296d..97f2a360 100644 --- a/roomserver/inthttp/server.go +++ b/roomserver/inthttp/server.go @@ -364,7 +364,7 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - internalAPIMux.Handle(RoomserverQuerySharedUsersPath, + internalAPIMux.Handle(RoomserverQueryKnownUsersPath, httputil.MakeInternalAPI("queryKnownUsers", func(req *http.Request) util.JSONResponse { request := api.QueryKnownUsersRequest{} response := api.QueryKnownUsersResponse{} diff --git a/syncapi/internal/keychange_test.go b/syncapi/internal/keychange_test.go index 6765fa65..92573baa 100644 --- a/syncapi/internal/keychange_test.go +++ b/syncapi/internal/keychange_test.go @@ -57,10 +57,6 @@ func (s *mockCurrentStateAPI) QueryCurrentState(ctx context.Context, req *api.Qu return nil } -func (s *mockCurrentStateAPI) QueryKnownUsers(ctx context.Context, req *api.QueryKnownUsersRequest, res *api.QueryKnownUsersResponse) error { - return nil -} - // QueryRoomsForUser retrieves a list of room IDs matching the given query. func (s *mockCurrentStateAPI) QueryRoomsForUser(ctx context.Context, req *api.QueryRoomsForUserRequest, res *api.QueryRoomsForUserResponse) error { return nil