mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-18 12:23:09 -06:00
Update room version checking code
This commit is contained in:
parent
a4401e3fb0
commit
fb3f97e9fe
|
|
@ -88,9 +88,22 @@ func MakeJoin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the room version of the room being joined
|
||||||
|
vQueryReq := api.QueryRoomVersionForRoomIDRequest{RoomID: roomID}
|
||||||
|
vQueryRes := api.QueryRoomVersionForRoomIDResponse{}
|
||||||
|
if e := query.QueryRoomVersionForRoomID(httpReq.Context(), &vQueryReq, &vQueryRes); e != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusInternalServerError,
|
||||||
|
JSON: jsonerror.Unknown(err.Error()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
JSON: map[string]interface{}{"event": builder},
|
JSON: map[string]interface{}{
|
||||||
|
"event": builder,
|
||||||
|
"room_version": vQueryRes.RoomVersion,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ type RoomEventDatabase interface {
|
||||||
// Look up the room version from the database.
|
// Look up the room version from the database.
|
||||||
GetRoomVersionForRoom(
|
GetRoomVersionForRoom(
|
||||||
ctx context.Context, roomNID types.RoomNID,
|
ctx context.Context, roomNID types.RoomNID,
|
||||||
) (state.StateResolutionVersion, error)
|
) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputRoomEventWriter has the APIs needed to write an event to the output logs.
|
// OutputRoomEventWriter has the APIs needed to write an event to the output logs.
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ type RoomserverQueryAPIDatabase interface {
|
||||||
// Look up the room version from the database.
|
// Look up the room version from the database.
|
||||||
GetRoomVersionForRoom(
|
GetRoomVersionForRoom(
|
||||||
ctx context.Context, roomNID types.RoomNID,
|
ctx context.Context, roomNID types.RoomNID,
|
||||||
) (state.StateResolutionVersion, error)
|
) (int64, error)
|
||||||
// Get the room NID for a given event ID.
|
// Get the room NID for a given event ID.
|
||||||
RoomNIDForEventID(
|
RoomNIDForEventID(
|
||||||
ctx context.Context, eventID string,
|
ctx context.Context, eventID string,
|
||||||
|
|
@ -627,17 +627,21 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
|
||||||
request *api.QueryStateAndAuthChainRequest,
|
request *api.QueryStateAndAuthChainRequest,
|
||||||
response *api.QueryStateAndAuthChainResponse,
|
response *api.QueryStateAndAuthChainResponse,
|
||||||
) error {
|
) error {
|
||||||
// TODO: get the correct room version
|
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||||
roomState, err := state.GetStateResolutionAlgorithm(state.StateResolutionAlgorithmV1, r.DB)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, roomNID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
roomState, err := state.GetStateResolutionAlgorithm(roomVersion, r.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
response.QueryStateAndAuthChainRequest = *request
|
response.QueryStateAndAuthChainRequest = *request
|
||||||
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if roomNID == 0 {
|
if roomNID == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetStateResolutionAlgorithm(
|
func GetStateResolutionAlgorithm(
|
||||||
version StateResolutionVersion, db database.RoomStateDatabase,
|
version int64, db database.RoomStateDatabase,
|
||||||
) (StateResolutionImpl, error) {
|
) (StateResolutionImpl, error) {
|
||||||
switch version {
|
switch version {
|
||||||
case StateResolutionAlgorithmV1:
|
case 1:
|
||||||
fallthrough
|
return Prepare(db, StateResolutionAlgorithmV1), nil
|
||||||
case StateResolutionAlgorithmV2:
|
case 2, 3, 4, 5:
|
||||||
return Prepare(db, version), nil
|
return Prepare(db, StateResolutionAlgorithmV2), nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported room version")
|
return nil, errors.New("unsupported room version")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,6 @@ type Database interface {
|
||||||
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool) ([]types.EventNID, error)
|
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool) ([]types.EventNID, error)
|
||||||
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
||||||
GetRoomVersionForRoom(ctx context.Context, roomNID types.RoomNID) (int64, error)
|
GetRoomVersionForRoom(ctx context.Context, roomNID types.RoomNID) (int64, error)
|
||||||
|
RoomNIDForEventID(ctx context.Context, eventID string) (types.RoomNID, error)
|
||||||
|
RoomNIDForEventNID(ctx context.Context, eventNID types.EventNID) (types.RoomNID, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
|
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -166,8 +165,8 @@ func (s *roomStatements) updateLatestEventNIDs(
|
||||||
|
|
||||||
func (s *roomStatements) selectRoomVersionForRoomNID(
|
func (s *roomStatements) selectRoomVersionForRoomNID(
|
||||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
||||||
) (state.StateResolutionVersion, error) {
|
) (int64, error) {
|
||||||
var roomVersion state.StateResolutionVersion
|
var roomVersion int64
|
||||||
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
||||||
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
||||||
return roomVersion, err
|
return roomVersion, err
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import (
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
|
||||||
"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/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
@ -737,7 +736,7 @@ func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]type
|
||||||
|
|
||||||
func (d *Database) GetRoomVersionForRoom(
|
func (d *Database) GetRoomVersionForRoom(
|
||||||
ctx context.Context, roomNID types.RoomNID,
|
ctx context.Context, roomNID types.RoomNID,
|
||||||
) (state.StateResolutionVersion, error) {
|
) (int64, error) {
|
||||||
return d.statements.selectRoomVersionForRoomNID(
|
return d.statements.selectRoomVersionForRoomNID(
|
||||||
ctx, nil, roomNID,
|
ctx, nil, roomNID,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -158,8 +157,8 @@ func (s *roomStatements) updateLatestEventNIDs(
|
||||||
|
|
||||||
func (s *roomStatements) selectRoomVersionForRoomNID(
|
func (s *roomStatements) selectRoomVersionForRoomNID(
|
||||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
||||||
) (state.StateResolutionVersion, error) {
|
) (int64, error) {
|
||||||
var roomVersion state.StateResolutionVersion
|
var roomVersion int64
|
||||||
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
||||||
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
||||||
return roomVersion, err
|
return roomVersion, err
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common"
|
"github.com/matrix-org/dendrite/common"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/state"
|
|
||||||
"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/dendrite/roomserver/version"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
@ -890,7 +889,7 @@ func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]type
|
||||||
|
|
||||||
func (d *Database) GetRoomVersionForRoom(
|
func (d *Database) GetRoomVersionForRoom(
|
||||||
ctx context.Context, roomNID types.RoomNID,
|
ctx context.Context, roomNID types.RoomNID,
|
||||||
) (state.StateResolutionVersion, error) {
|
) (int64, error) {
|
||||||
return d.statements.selectRoomVersionForRoomNID(
|
return d.statements.selectRoomVersionForRoomNID(
|
||||||
ctx, nil, roomNID,
|
ctx, nil, roomNID,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue