mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -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{
|
||||
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.
|
||||
GetRoomVersionForRoom(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (state.StateResolutionVersion, error)
|
||||
) (int64, error)
|
||||
}
|
||||
|
||||
// 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.
|
||||
GetRoomVersionForRoom(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (state.StateResolutionVersion, error)
|
||||
) (int64, error)
|
||||
// Get the room NID for a given event ID.
|
||||
RoomNIDForEventID(
|
||||
ctx context.Context, eventID string,
|
||||
|
|
@ -627,17 +627,21 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
|
|||
request *api.QueryStateAndAuthChainRequest,
|
||||
response *api.QueryStateAndAuthChainResponse,
|
||||
) error {
|
||||
// TODO: get the correct room version
|
||||
roomState, err := state.GetStateResolutionAlgorithm(state.StateResolutionAlgorithmV1, r.DB)
|
||||
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
response.QueryStateAndAuthChainRequest = *request
|
||||
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if roomNID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ const (
|
|||
)
|
||||
|
||||
func GetStateResolutionAlgorithm(
|
||||
version StateResolutionVersion, db database.RoomStateDatabase,
|
||||
version int64, db database.RoomStateDatabase,
|
||||
) (StateResolutionImpl, error) {
|
||||
switch version {
|
||||
case StateResolutionAlgorithmV1:
|
||||
fallthrough
|
||||
case StateResolutionAlgorithmV2:
|
||||
return Prepare(db, version), nil
|
||||
case 1:
|
||||
return Prepare(db, StateResolutionAlgorithmV1), nil
|
||||
case 2, 3, 4, 5:
|
||||
return Prepare(db, StateResolutionAlgorithmV2), nil
|
||||
default:
|
||||
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)
|
||||
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, 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/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
)
|
||||
|
||||
|
|
@ -166,8 +165,8 @@ func (s *roomStatements) updateLatestEventNIDs(
|
|||
|
||||
func (s *roomStatements) selectRoomVersionForRoomNID(
|
||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
||||
) (state.StateResolutionVersion, error) {
|
||||
var roomVersion state.StateResolutionVersion
|
||||
) (int64, error) {
|
||||
var roomVersion int64
|
||||
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
||||
return roomVersion, err
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
_ "github.com/lib/pq"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"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/version"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
|
@ -737,7 +736,7 @@ func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]type
|
|||
|
||||
func (d *Database) GetRoomVersionForRoom(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (state.StateResolutionVersion, error) {
|
||||
) (int64, error) {
|
||||
return d.statements.selectRoomVersionForRoomNID(
|
||||
ctx, nil, roomNID,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
"encoding/json"
|
||||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
"github.com/matrix-org/dendrite/roomserver/types"
|
||||
)
|
||||
|
||||
|
|
@ -158,8 +157,8 @@ func (s *roomStatements) updateLatestEventNIDs(
|
|||
|
||||
func (s *roomStatements) selectRoomVersionForRoomNID(
|
||||
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
|
||||
) (state.StateResolutionVersion, error) {
|
||||
var roomVersion state.StateResolutionVersion
|
||||
) (int64, error) {
|
||||
var roomVersion int64
|
||||
stmt := common.TxStmt(txn, s.selectRoomVersionForRoomNIDStmt)
|
||||
err := stmt.QueryRowContext(ctx, roomNID).Scan(&roomVersion)
|
||||
return roomVersion, err
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"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/version"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
|
@ -890,7 +889,7 @@ func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]type
|
|||
|
||||
func (d *Database) GetRoomVersionForRoom(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (state.StateResolutionVersion, error) {
|
||||
) (int64, error) {
|
||||
return d.statements.selectRoomVersionForRoomNID(
|
||||
ctx, nil, roomNID,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue