aboutsummaryrefslogtreecommitdiff
path: root/publicroomsapi/routing
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-03-19 11:04:08 +0000
committerGitHub <noreply@github.com>2020-03-19 11:04:08 +0000
commitbfbf96eec9152f61cb3e54154f1ed82148d82a8a (patch)
treefac798d74b4969e4bb5bdef82e2f0887ed2ea48f /publicroomsapi/routing
parentdc06c69887f7061411868b3a7a0ee8221a7053e1 (diff)
p2p: Implement published rooms (#923)
* Create and glue ExternalPublicRoomsProvider into the public rooms component This is how we will link p2p stuff to dendrite proper. * Use gmsl structs rather than our own * Implement federated public rooms - Make thirdparty endpoint r0 so riot-web loads the public room list * Typo * Missing callsites
Diffstat (limited to 'publicroomsapi/routing')
-rw-r--r--publicroomsapi/routing/routing.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/publicroomsapi/routing/routing.go b/publicroomsapi/routing/routing.go
index 1953e04f..321b61b8 100644
--- a/publicroomsapi/routing/routing.go
+++ b/publicroomsapi/routing/routing.go
@@ -24,6 +24,8 @@ import (
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/publicroomsapi/directory"
"github.com/matrix-org/dendrite/publicroomsapi/storage"
+ "github.com/matrix-org/dendrite/publicroomsapi/types"
+ "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
)
@@ -34,7 +36,10 @@ const pathPrefixR0 = "/_matrix/client/r0"
// Due to Setup being used to call many other functions, a gocyclo nolint is
// applied:
// nolint: gocyclo
-func Setup(apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database) {
+func Setup(
+ apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database,
+ fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider,
+) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
authData := auth.Data{
@@ -64,7 +69,17 @@ func Setup(apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.
).Methods(http.MethodPut, http.MethodOptions)
r0mux.Handle("/publicRooms",
common.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse {
+ if extRoomsProvider != nil {
+ return directory.GetPostPublicRoomsWithExternal(req, publicRoomsDB, fedClient, extRoomsProvider)
+ }
return directory.GetPostPublicRooms(req, publicRoomsDB)
}),
).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.
+ apiMux.Handle("/_matrix/federation/v1/publicRooms",
+ common.MakeExternalAPI("federation_public_rooms", func(req *http.Request) util.JSONResponse {
+ return directory.GetPostPublicRooms(req, publicRoomsDB)
+ }),
+ ).Methods(http.MethodGet)
}