Add wiring for querying the roomserver for the default room version

This commit is contained in:
Neil Alexander 2020-02-05 13:39:04 +00:00
parent 880d8ae024
commit 4eb7f5d75f
2 changed files with 42 additions and 0 deletions

View file

@ -244,6 +244,14 @@ type QueryServersInRoomAtEventResponse struct {
Servers []gomatrixserverlib.ServerName `json:"servers"` Servers []gomatrixserverlib.ServerName `json:"servers"`
} }
// QueryDefaultRoomVersion asks for the default room version
type QueryDefaultRoomVersionRequest struct{}
// QueryDefaultRoomVersionResponse is a response to QueryServersInRoomAtEventResponse
type QueryDefaultRoomVersionResponse struct {
RoomVersion int64
}
// 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.
@ -323,6 +331,13 @@ type RoomserverQueryAPI interface {
request *QueryServersInRoomAtEventRequest, request *QueryServersInRoomAtEventRequest,
response *QueryServersInRoomAtEventResponse, response *QueryServersInRoomAtEventResponse,
) error ) error
// Asks for the default room version as preferred by the server.
QueryDefaultRoomVersion(
ctx context.Context,
request *QueryDefaultRoomVersionRequest,
response *QueryDefaultRoomVersionResponse,
) error
} }
// RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API. // RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API.
@ -358,6 +373,9 @@ const RoomserverQueryBackfillPath = "/api/roomserver/queryBackfill"
// RoomserverQueryServersInRoomAtEventPath is the HTTP path for the QueryServersInRoomAtEvent API // RoomserverQueryServersInRoomAtEventPath is the HTTP path for the QueryServersInRoomAtEvent API
const RoomserverQueryServersInRoomAtEventPath = "/api/roomserver/queryServersInRoomAtEvents" const RoomserverQueryServersInRoomAtEventPath = "/api/roomserver/queryServersInRoomAtEvents"
// RoomserverQueryDefaultRoomVersionPath is the HTTP path for the QueryDefaultRoomVersion API
const RoomserverQueryDefaultRoomVersionPath = "/api/roomserver/queryDefaultRoomVersion"
// 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 {
@ -514,3 +532,16 @@ func (h *httpRoomserverQueryAPI) QueryServersInRoomAtEvent(
apiURL := h.roomserverURL + RoomserverQueryServersInRoomAtEventPath apiURL := h.roomserverURL + RoomserverQueryServersInRoomAtEventPath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response) return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
} }
// QueryServersInRoomAtEvent implements RoomServerQueryAPI
func (h *httpRoomserverQueryAPI) QueryDefaultRoomVersion(
ctx context.Context,
request *QueryDefaultRoomVersionRequest,
response *QueryDefaultRoomVersionResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryDefaultRoomVersion")
defer span.Finish()
apiURL := h.roomserverURL + RoomserverQueryDefaultRoomVersionPath
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}

View file

@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/roomserver/state" "github.com/matrix-org/dendrite/roomserver/state"
"github.com/matrix-org/dendrite/roomserver/state/database" "github.com/matrix-org/dendrite/roomserver/state/database"
"github.com/matrix-org/dendrite/roomserver/types" "github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/dendrite/roomserver/version"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
@ -723,6 +724,16 @@ func (r *RoomserverQueryAPI) QueryServersInRoomAtEvent(
return nil return nil
} }
// QueryDefaultRoomVersion implements api.RoomserverQueryAPI
func (r *RoomserverQueryAPI) QueryDefaultRoomVersion(
ctx context.Context,
request *api.QueryDefaultRoomVersionRequest,
response *api.QueryDefaultRoomVersionResponse,
) error {
response.RoomVersion = int64(version.GetDefaultRoomVersion())
return nil
}
// 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) {