mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Implement new RoomVersionImpl API (#3062)
As outlined in https://github.com/matrix-org/gomatrixserverlib/pull/368 The main change Dendrite side is that `RoomVersion` no longer has any methods on it. Instead, you need to bounce via `gmsl.GetRoomVersion`. It's very interesting to see where exactly Dendrite cares about this. For some places it's creating events (fine) but others are way more specific. Those areas will need to migrate to GMSL at some point.
This commit is contained in:
parent
71eeccf34a
commit
1647213fac
25 changed files with 144 additions and 65 deletions
|
@ -149,7 +149,12 @@ func IsInvitePending(
|
|||
return false, "", "", nil, fmt.Errorf("missing user for NID %d (%+v)", senderUserNIDs[0], senderUsers)
|
||||
}
|
||||
|
||||
event, err := info.RoomVersion.NewEventFromTrustedJSON(eventJSON, false)
|
||||
verImpl, err := gomatrixserverlib.GetRoomVersion(info.RoomVersion)
|
||||
if err != nil {
|
||||
return false, "", "", nil, err
|
||||
}
|
||||
|
||||
event, err := verImpl.NewEventFromTrustedJSON(eventJSON, false)
|
||||
|
||||
return true, senderUser, userNIDToEventID[senderUserNIDs[0]], event, err
|
||||
}
|
||||
|
|
|
@ -838,6 +838,11 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
|
|||
trace, ctx := internal.StartRegion(ctx, "lookupEvent")
|
||||
defer trace.EndRegion()
|
||||
|
||||
verImpl, err := gomatrixserverlib.GetRoomVersion(roomVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if localFirst {
|
||||
// fetch from the roomserver
|
||||
events, err := t.db.EventsFromIDs(ctx, t.roomInfo, []string{missingEventID})
|
||||
|
@ -865,7 +870,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
|
|||
}
|
||||
continue
|
||||
}
|
||||
event, err = roomVersion.NewEventFromUntrustedJSON(txn.PDUs[0])
|
||||
event, err = verImpl.NewEventFromUntrustedJSON(txn.PDUs[0])
|
||||
if err != nil {
|
||||
t.log.WithError(err).WithField("missing_event_id", missingEventID).Warnf("Failed to parse event JSON of event returned from /event")
|
||||
continue
|
||||
|
|
|
@ -35,7 +35,7 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
|||
ctx, cancel := context.WithDeadline(processCtx.Context(), deadline)
|
||||
defer cancel()
|
||||
|
||||
event, err := gomatrixserverlib.RoomVersionV6.NewEventFromTrustedJSON(
|
||||
event, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV6).NewEventFromTrustedJSON(
|
||||
[]byte(`{"auth_events":[],"content":{"creator":"@neilalexander:dendrite.matrix.org","room_version":"6"},"depth":1,"hashes":{"sha256":"jqOqdNEH5r0NiN3xJtj0u5XUVmRqq9YvGbki1wxxuuM"},"origin":"dendrite.matrix.org","origin_server_ts":1644595362726,"prev_events":[],"prev_state":[],"room_id":"!jSZZRknA6GkTBXNP:dendrite.matrix.org","sender":"@neilalexander:dendrite.matrix.org","signatures":{"dendrite.matrix.org":{"ed25519:6jB2aB":"bsQXO1wketf1OSe9xlndDIWe71W9KIundc6rBw4KEZdGPW7x4Tv4zDWWvbxDsG64sS2IPWfIm+J0OOozbrWIDw"}},"state_key":"","type":"m.room.create"}`),
|
||||
false,
|
||||
)
|
||||
|
|
|
@ -884,12 +884,14 @@ func (r *Queryer) QueryRestrictedJoinAllowed(ctx context.Context, req *api.Query
|
|||
if roomInfo == nil || roomInfo.IsStub() {
|
||||
return nil // fmt.Errorf("room %q doesn't exist or is stub room", req.RoomID)
|
||||
}
|
||||
verImpl, err := gomatrixserverlib.GetRoomVersion(roomInfo.RoomVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// If the room version doesn't allow restricted joins then don't
|
||||
// try to process any further.
|
||||
allowRestrictedJoins, err := roomInfo.RoomVersion.MayAllowRestrictedJoinsInEventAuth()
|
||||
if err != nil {
|
||||
return fmt.Errorf("roomInfo.RoomVersion.AllowRestrictedJoinsInEventAuth: %w", err)
|
||||
} else if !allowRestrictedJoins {
|
||||
allowRestrictedJoins := verImpl.MayAllowRestrictedJoinsInEventAuth()
|
||||
if !allowRestrictedJoins {
|
||||
return nil
|
||||
}
|
||||
// Start off by populating the "resident" flag in the response. If we
|
||||
|
|
|
@ -54,7 +54,7 @@ func (db *getEventDB) addFakeEvent(eventID string, authIDs []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
event, err := gomatrixserverlib.RoomVersionV1.NewEventFromTrustedJSON(
|
||||
event, err := gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersionV1).NewEventFromTrustedJSON(
|
||||
eventJSON, false,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue