diff options
author | kegsay <kegan@matrix.org> | 2023-04-21 17:06:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-21 17:06:29 +0100 |
commit | 1647213facae52e2c8889fbc848ffc5d3a5792f0 (patch) | |
tree | 684206b99582df20ae144e19db37591cc35b789d /federationapi/routing | |
parent | 71eeccf34a2ea4434c315c19778d80a7b2469270 (diff) |
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.
Diffstat (limited to 'federationapi/routing')
-rw-r--r-- | federationapi/routing/invite.go | 8 | ||||
-rw-r--r-- | federationapi/routing/join.go | 19 | ||||
-rw-r--r-- | federationapi/routing/leave.go | 14 | ||||
-rw-r--r-- | federationapi/routing/threepid.go | 7 |
4 files changed, 37 insertions, 11 deletions
diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index e9dbdb7d..b13e59f0 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -22,7 +22,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/roomserver/api" - roomserverVersion "github.com/matrix-org/dendrite/roomserver/version" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/fclient" @@ -78,7 +77,7 @@ func InviteV1( ) util.JSONResponse { roomVer := gomatrixserverlib.RoomVersionV1 body := request.Content() - event, err := roomVer.NewEventFromTrustedJSON(body, false) + event, err := gomatrixserverlib.MustGetRoomVersion(roomVer).NewEventFromTrustedJSON(body, false) switch err.(type) { case gomatrixserverlib.BadJSONError: return util.JSONResponse{ @@ -116,7 +115,8 @@ func processInvite( ) util.JSONResponse { // Check that we can accept invites for this room version. - if _, err := roomserverVersion.SupportedRoomVersion(roomVer); err != nil { + verImpl, err := gomatrixserverlib.GetRoomVersion(roomVer) + if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, JSON: jsonerror.UnsupportedRoomVersion( @@ -157,7 +157,7 @@ func processInvite( } // Check that the event is signed by the server sending the request. - redacted, err := event.Version().RedactEventJSON(event.JSON()) + redacted, err := verImpl.RedactEventJSON(event.JSON()) if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, diff --git a/federationapi/routing/join.go b/federationapi/routing/join.go index 50a2fd1a..0d83a2af 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -206,8 +206,17 @@ func SendJoin( JSON: jsonerror.InternalServerError(), } } + verImpl, err := gomatrixserverlib.GetRoomVersion(verRes.RoomVersion) + if err != nil { + return util.JSONResponse{ + Code: http.StatusInternalServerError, + JSON: jsonerror.UnsupportedRoomVersion( + fmt.Sprintf("QueryRoomVersionForRoom returned unknown room version: %s", verRes.RoomVersion), + ), + } + } - event, err := verRes.RoomVersion.NewEventFromUntrustedJSON(request.Content()) + event, err := verImpl.NewEventFromUntrustedJSON(request.Content()) if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, @@ -287,7 +296,7 @@ func SendJoin( } // Check that the event is signed by the server sending the request. - redacted, err := event.Version().RedactEventJSON(event.JSON()) + redacted, err := verImpl.RedactEventJSON(event.JSON()) if err != nil { logrus.WithError(err).Errorf("XXX: join.go") return util.JSONResponse{ @@ -461,9 +470,11 @@ func checkRestrictedJoin( roomVersion gomatrixserverlib.RoomVersion, roomID, userID string, ) (*util.JSONResponse, string, error) { - if allowRestricted, err := roomVersion.MayAllowRestrictedJoinsInEventAuth(); err != nil { + verImpl, err := gomatrixserverlib.GetRoomVersion(roomVersion) + if err != nil { return nil, "", err - } else if !allowRestricted { + } + if !verImpl.MayAllowRestrictedJoinsInEventAuth() { return nil, "", nil } req := &api.QueryRestrictedJoinAllowedRequest{ diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index b003c1cd..d189cc53 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -149,8 +149,18 @@ func SendLeave( } } + verImpl, err := gomatrixserverlib.GetRoomVersion(verRes.RoomVersion) + if err != nil { + return util.JSONResponse{ + Code: http.StatusInternalServerError, + JSON: jsonerror.UnsupportedRoomVersion( + fmt.Sprintf("QueryRoomVersionForRoom returned unknown version: %s", verRes.RoomVersion), + ), + } + } + // Decode the event JSON from the request. - event, err := verRes.RoomVersion.NewEventFromUntrustedJSON(request.Content()) + event, err := verImpl.NewEventFromUntrustedJSON(request.Content()) switch err.(type) { case gomatrixserverlib.BadJSONError: return util.JSONResponse{ @@ -253,7 +263,7 @@ func SendLeave( } // Check that the event is signed by the server sending the request. - redacted, err := event.Version().RedactEventJSON(event.JSON()) + redacted, err := verImpl.RedactEventJSON(event.JSON()) if err != nil { logrus.WithError(err).Errorf("XXX: leave.go") return util.JSONResponse{ diff --git a/federationapi/routing/threepid.go b/federationapi/routing/threepid.go index 831f3c61..31f29fd3 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -196,7 +196,12 @@ func ExchangeThirdPartyInvite( util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed") return jsonerror.InternalServerError() } - inviteEvent, err := verRes.RoomVersion.NewEventFromUntrustedJSON(signedEvent.Event) + verImpl, err := gomatrixserverlib.GetRoomVersion(verRes.RoomVersion) + if err != nil { + util.GetLogger(httpReq.Context()).WithError(err).Errorf("unknown room version: %s", verRes.RoomVersion) + return jsonerror.InternalServerError() + } + inviteEvent, err := verImpl.NewEventFromUntrustedJSON(signedEvent.Event) if err != nil { util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed") return jsonerror.InternalServerError() |