mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Add support for server query param in publicrooms
This commit is contained in:
parent
0b732d6f45
commit
cc972a8b94
|
|
@ -21,6 +21,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
"github.com/matrix-org/dendrite/publicroomsapi/storage"
|
||||||
|
|
@ -41,12 +43,25 @@ type filter struct {
|
||||||
|
|
||||||
// GetPostPublicRooms implements GET and POST /publicRooms
|
// GetPostPublicRooms implements GET and POST /publicRooms
|
||||||
func GetPostPublicRooms(
|
func GetPostPublicRooms(
|
||||||
req *http.Request, publicRoomDatabase storage.Database,
|
req *http.Request, cfg *config.Dendrite, server gomatrixserverlib.ServerName,
|
||||||
|
publicRoomDatabase storage.Database, fedClient *gomatrixserverlib.FederationClient,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
var request PublicRoomReq
|
var request PublicRoomReq
|
||||||
if fillErr := fillPublicRoomsReq(req, &request); fillErr != nil {
|
if fillErr := fillPublicRoomsReq(req, &request); fillErr != nil {
|
||||||
return *fillErr
|
return *fillErr
|
||||||
}
|
}
|
||||||
|
if server != "" && server != cfg.Matrix.ServerName {
|
||||||
|
//TODO Authenticate user before serving rooms from other server
|
||||||
|
fres, err := fedClient.GetPublicRooms(req.Context(), server, int(request.Limit),
|
||||||
|
request.Since, false, "")
|
||||||
|
if err != nil {
|
||||||
|
return jsonerror.InternalServerError()
|
||||||
|
}
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusOK,
|
||||||
|
JSON: fres,
|
||||||
|
}
|
||||||
|
}
|
||||||
response, err := publicRooms(req.Context(), request, publicRoomDatabase)
|
response, err := publicRooms(req.Context(), request, publicRoomDatabase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
|
|
|
||||||
|
|
@ -47,5 +47,5 @@ func SetupPublicRoomsAPIComponent(
|
||||||
logrus.WithError(err).Panic("failed to start public rooms server consumer")
|
logrus.WithError(err).Panic("failed to start public rooms server consumer")
|
||||||
}
|
}
|
||||||
|
|
||||||
routing.Setup(base.APIMux, deviceDB, publicRoomsDB, fedClient, extRoomsProvider)
|
routing.Setup(base.APIMux, base.Cfg, deviceDB, publicRoomsDB, fedClient, extRoomsProvider)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ package routing
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth"
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
|
|
@ -37,7 +39,7 @@ const pathPrefixR0 = "/_matrix/client/r0"
|
||||||
// applied:
|
// applied:
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func Setup(
|
func Setup(
|
||||||
apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database,
|
apiMux *mux.Router, cfg *config.Dendrite, deviceDB devices.Database, publicRoomsDB storage.Database,
|
||||||
fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider,
|
fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider,
|
||||||
) {
|
) {
|
||||||
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
|
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
|
||||||
|
|
@ -72,14 +74,15 @@ func Setup(
|
||||||
if extRoomsProvider != nil {
|
if extRoomsProvider != nil {
|
||||||
return directory.GetPostPublicRoomsWithExternal(req, publicRoomsDB, fedClient, extRoomsProvider)
|
return directory.GetPostPublicRoomsWithExternal(req, publicRoomsDB, fedClient, extRoomsProvider)
|
||||||
}
|
}
|
||||||
return directory.GetPostPublicRooms(req, publicRoomsDB)
|
server := gomatrixserverlib.ServerName(req.URL.Query().Get("server"))
|
||||||
|
return directory.GetPostPublicRooms(req, cfg, server, publicRoomsDB, fedClient)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
||||||
|
|
||||||
// Federation - TODO: should this live here or in federation API? It's sure easier if it's here so here it is.
|
// Federation - TODO: should this live here or in federation API? It's sure easier if it's here so here it is.
|
||||||
apiMux.Handle("/_matrix/federation/v1/publicRooms",
|
apiMux.Handle("/_matrix/federation/v1/publicRooms",
|
||||||
common.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse {
|
common.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse {
|
||||||
return directory.GetPostPublicRooms(req, publicRoomsDB)
|
return directory.GetPostPublicRooms(req, cfg, cfg.Matrix.ServerName, publicRoomsDB, fedClient)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodGet)
|
).Methods(http.MethodGet)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue