diff options
author | kegsay <kegan@matrix.org> | 2023-04-20 19:07:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 19:07:31 +0100 |
commit | 71eeccf34a2ea4434c315c19778d80a7b2469270 (patch) | |
tree | e6d5bd8f91a9a90b2b076f842c183bae332c6311 /federationapi | |
parent | 72285b2659a31ebd52c91799c17105d81d996f40 (diff) |
refactor: funnel event creation through room versions (#3060)
In preparation of interfacing up the room version value.
Diffstat (limited to 'federationapi')
-rw-r--r-- | federationapi/federationapi_test.go | 2 | ||||
-rw-r--r-- | federationapi/internal/perform.go | 6 | ||||
-rw-r--r-- | federationapi/queue/queue_test.go | 2 | ||||
-rw-r--r-- | federationapi/routing/invite.go | 4 | ||||
-rw-r--r-- | federationapi/routing/join.go | 4 | ||||
-rw-r--r-- | federationapi/routing/leave.go | 4 | ||||
-rw-r--r-- | federationapi/routing/threepid.go | 2 |
7 files changed, 12 insertions, 12 deletions
diff --git a/federationapi/federationapi_test.go b/federationapi/federationapi_test.go index a8af0000..bef17559 100644 --- a/federationapi/federationapi_test.go +++ b/federationapi/federationapi_test.go @@ -321,7 +321,7 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) { ) for _, tc := range testCases { - ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(tc.eventJSON), false, tc.roomVer) + ev, err := tc.roomVer.NewEventFromTrustedJSON([]byte(tc.eventJSON), false) if err != nil { t.Errorf("failed to parse event: %s", err) } diff --git a/federationapi/internal/perform.go b/federationapi/internal/perform.go index 62a08e88..2ef8b552 100644 --- a/federationapi/internal/perform.go +++ b/federationapi/internal/perform.go @@ -235,7 +235,7 @@ func (r *FederationInternalAPI) performJoinUsingServer( // contain signatures that we don't know about. if len(respSendJoin.Event) > 0 { var remoteEvent *gomatrixserverlib.Event - remoteEvent, err = gomatrixserverlib.UntrustedEvent(respSendJoin.Event, respMakeJoin.RoomVersion) + remoteEvent, err = respMakeJoin.RoomVersion.NewEventFromUntrustedJSON(respSendJoin.Event) if err == nil && isWellFormedMembershipEvent( remoteEvent, roomID, userID, ) { @@ -660,7 +660,7 @@ func (r *FederationInternalAPI) PerformInvite( return fmt.Errorf("r.federation.SendInviteV2: failed to send invite: %w", err) } - inviteEvent, err := gomatrixserverlib.UntrustedEvent(inviteRes.Event, request.RoomVersion) + inviteEvent, err := request.RoomVersion.NewEventFromUntrustedJSON(inviteRes.Event) if err != nil { return fmt.Errorf("r.federation.SendInviteV2 failed to decode event response: %w", err) } @@ -808,7 +808,7 @@ func federatedAuthProvider( // event ID again. for _, pdu := range tx.PDUs { // Try to parse the event. - ev, everr := gomatrixserverlib.NewEventFromUntrustedJSON(pdu, roomVersion) + ev, everr := roomVersion.NewEventFromUntrustedJSON(pdu) if everr != nil { return nil, fmt.Errorf("missingAuth gomatrixserverlib.NewEventFromUntrustedJSON: %w", everr) } diff --git a/federationapi/queue/queue_test.go b/federationapi/queue/queue_test.go index b153cba0..77b44446 100644 --- a/federationapi/queue/queue_test.go +++ b/federationapi/queue/queue_test.go @@ -105,7 +105,7 @@ func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent { t.Helper() content := `{"type":"m.room.message"}` - ev, err := gomatrixserverlib.NewEventFromTrustedJSON([]byte(content), false, gomatrixserverlib.RoomVersionV10) + ev, err := gomatrixserverlib.RoomVersionV10.NewEventFromTrustedJSON([]byte(content), false) if err != nil { t.Fatalf("failed to create event: %v", err) } diff --git a/federationapi/routing/invite.go b/federationapi/routing/invite.go index b188041e..e9dbdb7d 100644 --- a/federationapi/routing/invite.go +++ b/federationapi/routing/invite.go @@ -78,7 +78,7 @@ func InviteV1( ) util.JSONResponse { roomVer := gomatrixserverlib.RoomVersionV1 body := request.Content() - event, err := gomatrixserverlib.NewEventFromTrustedJSON(body, false, roomVer) + event, err := roomVer.NewEventFromTrustedJSON(body, false) switch err.(type) { case gomatrixserverlib.BadJSONError: return util.JSONResponse{ @@ -157,7 +157,7 @@ func processInvite( } // Check that the event is signed by the server sending the request. - redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) + redacted, err := event.Version().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 750d5ce9..50a2fd1a 100644 --- a/federationapi/routing/join.go +++ b/federationapi/routing/join.go @@ -207,7 +207,7 @@ func SendJoin( } } - event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion) + event, err := verRes.RoomVersion.NewEventFromUntrustedJSON(request.Content()) if err != nil { return util.JSONResponse{ Code: http.StatusBadRequest, @@ -287,7 +287,7 @@ func SendJoin( } // Check that the event is signed by the server sending the request. - redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) + redacted, err := event.Version().RedactEventJSON(event.JSON()) if err != nil { logrus.WithError(err).Errorf("XXX: join.go") return util.JSONResponse{ diff --git a/federationapi/routing/leave.go b/federationapi/routing/leave.go index afd4b24a..b003c1cd 100644 --- a/federationapi/routing/leave.go +++ b/federationapi/routing/leave.go @@ -150,7 +150,7 @@ func SendLeave( } // Decode the event JSON from the request. - event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion) + event, err := verRes.RoomVersion.NewEventFromUntrustedJSON(request.Content()) switch err.(type) { case gomatrixserverlib.BadJSONError: return util.JSONResponse{ @@ -253,7 +253,7 @@ func SendLeave( } // Check that the event is signed by the server sending the request. - redacted, err := gomatrixserverlib.RedactEventJSON(event.JSON(), event.Version()) + redacted, err := event.Version().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 ccdca482..831f3c61 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -196,7 +196,7 @@ func ExchangeThirdPartyInvite( util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed") return jsonerror.InternalServerError() } - inviteEvent, err := gomatrixserverlib.UntrustedEvent(signedEvent.Event, verRes.RoomVersion) + inviteEvent, err := verRes.RoomVersion.NewEventFromUntrustedJSON(signedEvent.Event) if err != nil { util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed") return jsonerror.InternalServerError() |