mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-13 09:53:10 -06:00
Implement new ReserveRoomID in CreateRoom
This commit is contained in:
parent
30c65f1352
commit
a6d47d2fa9
|
|
@ -23,7 +23,6 @@ import (
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||||
|
|
@ -33,6 +32,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
|
// https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
|
||||||
|
|
@ -90,10 +90,24 @@ type fledglingEvent struct {
|
||||||
func CreateRoom(req *http.Request, device *authtypes.Device,
|
func CreateRoom(req *http.Request, device *authtypes.Device,
|
||||||
cfg config.Dendrite, producer *producers.RoomserverProducer,
|
cfg config.Dendrite, producer *producers.RoomserverProducer,
|
||||||
accountDB *accounts.Database, aliasAPI api.RoomserverAliasAPI,
|
accountDB *accounts.Database, aliasAPI api.RoomserverAliasAPI,
|
||||||
|
queryAPI api.RoomserverQueryAPI,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
// TODO (#267): Check room ID doesn't clash with an existing one, and we
|
// Generate a room ID and reserve it.
|
||||||
// probably shouldn't be using pseudo-random strings, maybe GUIDs?
|
// Keep trying until we have one which is unused.
|
||||||
roomID := fmt.Sprintf("!%s:%s", util.RandomString(16), cfg.Matrix.ServerName)
|
var roomID string
|
||||||
|
for roomID == "" {
|
||||||
|
checkRoomID := util.RandomString(16)
|
||||||
|
checkRoomID = fmt.Sprintf("!%s:%s", checkRoomID, cfg.Matrix.ServerName)
|
||||||
|
|
||||||
|
queryReq := api.QueryReserveRoomIDRequest{RoomID: checkRoomID}
|
||||||
|
var queryResp api.QueryReserveRoomIDResponse
|
||||||
|
queryAPI.QueryReserveRoomID(req.Context(), &queryReq, &queryResp)
|
||||||
|
|
||||||
|
if queryResp.Success {
|
||||||
|
roomID = checkRoomID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return createRoom(req, device, cfg, roomID, producer, accountDB, aliasAPI)
|
return createRoom(req, device, cfg, roomID, producer, accountDB, aliasAPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func Setup(
|
||||||
|
|
||||||
r0mux.Handle("/createRoom",
|
r0mux.Handle("/createRoom",
|
||||||
common.MakeAuthAPI("createRoom", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
common.MakeAuthAPI("createRoom", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||||
return CreateRoom(req, device, cfg, producer, accountDB, aliasAPI)
|
return CreateRoom(req, device, cfg, producer, accountDB, aliasAPI, queryAPI)
|
||||||
}),
|
}),
|
||||||
).Methods("POST", "OPTIONS")
|
).Methods("POST", "OPTIONS")
|
||||||
r0mux.Handle("/join/{roomIDOrAlias}",
|
r0mux.Handle("/join/{roomIDOrAlias}",
|
||||||
|
|
|
||||||
|
|
@ -209,6 +209,13 @@ type RoomserverQueryAPI interface {
|
||||||
request *QueryServerAllowedToSeeEventRequest,
|
request *QueryServerAllowedToSeeEventRequest,
|
||||||
response *QueryServerAllowedToSeeEventResponse,
|
response *QueryServerAllowedToSeeEventResponse,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
|
// Query if a room ID is available and reserve it.
|
||||||
|
QueryReserveRoomID(
|
||||||
|
ctx context.Context,
|
||||||
|
request *QueryReserveRoomIDRequest,
|
||||||
|
response *QueryReserveRoomIDResponse,
|
||||||
|
) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API.
|
// RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue