mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33:09 -06:00
Create roomserver QueryReserveRoomID
TODO: Query prefix is not really correct for this specific query because it will not do readonly stuff. Maybe rename it?
This commit is contained in:
parent
32a2b3a5c0
commit
be7a785e52
|
|
@ -21,10 +21,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
|
||||||
"github.com/opentracing/opentracing-go"
|
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -155,6 +154,18 @@ type QueryServerAllowedToSeeEventResponse struct {
|
||||||
AllowedToSeeEvent bool `json:"can_see_event"`
|
AllowedToSeeEvent bool `json:"can_see_event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryReserveRoomIDRequest is a request to QueryServerAllowedToSeeEvent
|
||||||
|
type QueryReserveRoomIDRequest struct {
|
||||||
|
// TODO: Docs
|
||||||
|
RoomID string `json:"room_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryReserveRoomIDResponse is a response to QueryServerAllowedToSeeEvent
|
||||||
|
type QueryReserveRoomIDResponse struct {
|
||||||
|
// TODO: Docs
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
// RoomserverQueryAPI is used to query information from the room server.
|
// RoomserverQueryAPI is used to query information from the room server.
|
||||||
type RoomserverQueryAPI interface {
|
type RoomserverQueryAPI interface {
|
||||||
// Query the latest events and state for a room from the room server.
|
// Query the latest events and state for a room from the room server.
|
||||||
|
|
@ -218,6 +229,9 @@ const RoomserverQueryInvitesForUserPath = "/api/roomserver/queryInvitesForUser"
|
||||||
// RoomserverQueryServerAllowedToSeeEventPath is the HTTP path for the QueryServerAllowedToSeeEvent API
|
// RoomserverQueryServerAllowedToSeeEventPath is the HTTP path for the QueryServerAllowedToSeeEvent API
|
||||||
const RoomserverQueryServerAllowedToSeeEventPath = "/api/roomserver/queryServerAllowedToSeeEvent"
|
const RoomserverQueryServerAllowedToSeeEventPath = "/api/roomserver/queryServerAllowedToSeeEvent"
|
||||||
|
|
||||||
|
// RoomserverQueryReserveRoomIDPath is the HTTP path for the QueryReserveRoomID API
|
||||||
|
const RoomserverQueryReserveRoomIDPath = "/api/roomserver/queryReserveRoomID"
|
||||||
|
|
||||||
// NewRoomserverQueryAPIHTTP creates a RoomserverQueryAPI implemented by talking to a HTTP POST API.
|
// NewRoomserverQueryAPIHTTP creates a RoomserverQueryAPI implemented by talking to a HTTP POST API.
|
||||||
// If httpClient is nil then it uses the http.DefaultClient
|
// If httpClient is nil then it uses the http.DefaultClient
|
||||||
func NewRoomserverQueryAPIHTTP(roomserverURL string, httpClient *http.Client) RoomserverQueryAPI {
|
func NewRoomserverQueryAPIHTTP(roomserverURL string, httpClient *http.Client) RoomserverQueryAPI {
|
||||||
|
|
@ -310,6 +324,19 @@ func (h *httpRoomserverQueryAPI) QueryServerAllowedToSeeEvent(
|
||||||
return postJSON(ctx, span, h.httpClient, apiURL, request, response)
|
return postJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Docs
|
||||||
|
func (h *httpRoomserverQueryAPI) QueryReserveRoomID(
|
||||||
|
ctx context.Context,
|
||||||
|
request *QueryReserveRoomIDRequest,
|
||||||
|
response *QueryReserveRoomIDResponse,
|
||||||
|
) (err error) {
|
||||||
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryReserveRoomID")
|
||||||
|
defer span.Finish()
|
||||||
|
|
||||||
|
apiURL := h.roomserverURL + RoomserverQueryReserveRoomIDPath
|
||||||
|
return postJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||||
|
}
|
||||||
|
|
||||||
func postJSON(
|
func postJSON(
|
||||||
ctx context.Context, span opentracing.Span, httpClient *http.Client,
|
ctx context.Context, span opentracing.Span, httpClient *http.Client,
|
||||||
apiURL string, request, response interface{},
|
apiURL string, request, response interface{},
|
||||||
|
|
|
||||||
|
|
@ -418,6 +418,23 @@ func (r *RoomserverQueryAPI) QueryServerAllowedToSeeEvent(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryReserveRoomID implements api.RoomserverQueryAPI
|
||||||
|
func (r *RoomserverQueryAPI) QueryReserveRoomID(
|
||||||
|
ctx context.Context,
|
||||||
|
request *api.QueryReserveRoomIDRequest,
|
||||||
|
response *api.QueryReserveRoomIDResponse,
|
||||||
|
) error {
|
||||||
|
nid, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||||
|
if nid != 0 {
|
||||||
|
response.Success = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success = true
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// SetupHTTP adds the RoomserverQueryAPI handlers to the http.ServeMux.
|
// SetupHTTP adds the RoomserverQueryAPI handlers to the http.ServeMux.
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux) {
|
func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux) {
|
||||||
|
|
@ -505,4 +522,18 @@ func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux) {
|
||||||
return util.JSONResponse{Code: 200, JSON: &response}
|
return util.JSONResponse{Code: 200, JSON: &response}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
servMux.Handle(
|
||||||
|
api.RoomserverQueryReserveRoomIDPath,
|
||||||
|
common.MakeInternalAPI("queryReserveRoomID", func(req *http.Request) util.JSONResponse {
|
||||||
|
var request api.QueryReserveRoomIDRequest
|
||||||
|
var response api.QueryReserveRoomIDResponse
|
||||||
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
|
if err := r.QueryReserveRoomID(req.Context(), &request, &response); err != nil {
|
||||||
|
return util.ErrorResponse(err)
|
||||||
|
}
|
||||||
|
return util.JSONResponse{Code: 200, JSON: &response}
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue