Pull context out of invite input structs

This commit is contained in:
Devon Hudson 2023-05-24 10:28:34 -06:00
parent d93f03c445
commit a4fc905f8d
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
4 changed files with 14 additions and 16 deletions

View file

@ -15,6 +15,7 @@
package routing package routing
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -76,7 +77,6 @@ func InviteV2(
} }
input := gomatrixserverlib.HandleInviteInput{ input := gomatrixserverlib.HandleInviteInput{
Context: httpReq.Context(),
RoomVersion: inviteReq.RoomVersion(), RoomVersion: inviteReq.RoomVersion(),
RoomID: roomID, RoomID: roomID,
EventID: eventID, EventID: eventID,
@ -90,7 +90,7 @@ func InviteV2(
InviteEvent: inviteReq.Event(), InviteEvent: inviteReq.Event(),
StrippedState: inviteReq.InviteRoomState(), StrippedState: inviteReq.InviteRoomState(),
} }
event, jsonErr := handleInvite(input, rsAPI) event, jsonErr := handleInvite(httpReq.Context(), input, rsAPI)
if jsonErr != nil { if jsonErr != nil {
return *jsonErr return *jsonErr
} }
@ -161,7 +161,6 @@ func InviteV1(
} }
input := gomatrixserverlib.HandleInviteInput{ input := gomatrixserverlib.HandleInviteInput{
Context: httpReq.Context(),
RoomVersion: roomVer, RoomVersion: roomVer,
RoomID: roomID, RoomID: roomID,
EventID: eventID, EventID: eventID,
@ -175,7 +174,7 @@ func InviteV1(
InviteEvent: event, InviteEvent: event,
StrippedState: strippedState, StrippedState: strippedState,
} }
event, jsonErr := handleInvite(input, rsAPI) event, jsonErr := handleInvite(httpReq.Context(), input, rsAPI)
if jsonErr != nil { if jsonErr != nil {
return *jsonErr return *jsonErr
} }
@ -185,18 +184,18 @@ func InviteV1(
} }
} }
func handleInvite(input gomatrixserverlib.HandleInviteInput, rsAPI api.FederationRoomserverAPI) (gomatrixserverlib.PDU, *util.JSONResponse) { func handleInvite(ctx context.Context, input gomatrixserverlib.HandleInviteInput, rsAPI api.FederationRoomserverAPI) (gomatrixserverlib.PDU, *util.JSONResponse) {
inviteEvent, err := gomatrixserverlib.HandleInvite(input) inviteEvent, err := gomatrixserverlib.HandleInvite(ctx, input)
switch e := err.(type) { switch e := err.(type) {
case nil: case nil:
case spec.InternalServerError: case spec.InternalServerError:
util.GetLogger(input.Context).WithError(err) util.GetLogger(ctx).WithError(err)
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusInternalServerError, Code: http.StatusInternalServerError,
JSON: spec.InternalServerError{}, JSON: spec.InternalServerError{},
} }
case spec.MatrixError: case spec.MatrixError:
util.GetLogger(input.Context).WithError(err) util.GetLogger(ctx).WithError(err)
code := http.StatusInternalServerError code := http.StatusInternalServerError
switch e.ErrCode { switch e.ErrCode {
case spec.ErrorForbidden: case spec.ErrorForbidden:
@ -212,7 +211,7 @@ func handleInvite(input gomatrixserverlib.HandleInviteInput, rsAPI api.Federatio
JSON: e, JSON: e,
} }
default: default:
util.GetLogger(input.Context).WithError(err) util.GetLogger(ctx).WithError(err)
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: spec.Unknown("unknown error"), JSON: spec.Unknown("unknown error"),
@ -220,8 +219,8 @@ func handleInvite(input gomatrixserverlib.HandleInviteInput, rsAPI api.Federatio
} }
headeredInvite := &types.HeaderedEvent{PDU: inviteEvent} headeredInvite := &types.HeaderedEvent{PDU: inviteEvent}
if err = rsAPI.HandleInvite(input.Context, headeredInvite); err != nil { if err = rsAPI.HandleInvite(ctx, headeredInvite); err != nil {
util.GetLogger(input.Context).WithError(err).Error("HandleInvite failed") util.GetLogger(ctx).WithError(err).Error("HandleInvite failed")
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusInternalServerError, Code: http.StatusInternalServerError,
JSON: spec.InternalServerError{}, JSON: spec.InternalServerError{},

2
go.mod
View file

@ -22,7 +22,7 @@ require (
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
github.com/matrix-org/gomatrixserverlib v0.0.0-20230524155842-456850e19e68 github.com/matrix-org/gomatrixserverlib v0.0.0-20230524162524-cfd2b5c1046f
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
github.com/mattn/go-sqlite3 v1.14.16 github.com/mattn/go-sqlite3 v1.14.16

4
go.sum
View file

@ -323,8 +323,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91 h1:s7fexw
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo=
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 h1:kHKxCOLcHH8r4Fzarl4+Y3K5hjothkVW5z7T1dUM11U=
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s= github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230524155842-456850e19e68 h1:Zf62GOLrN2VqifAreL5xjmnSKe7uz9J+ttj7AdeJ8ts= github.com/matrix-org/gomatrixserverlib v0.0.0-20230524162524-cfd2b5c1046f h1:64K53Gd4mPI9FBWAUV9KhSOrgC33JBxj5d0A2k8iID8=
github.com/matrix-org/gomatrixserverlib v0.0.0-20230524155842-456850e19e68/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU= github.com/matrix-org/gomatrixserverlib v0.0.0-20230524162524-cfd2b5c1046f/go.mod h1:H9V9N3Uqn1bBJqYJNGK1noqtgJTaCEhtTdcH/mp50uU=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a h1:awrPDf9LEFySxTLKYBMCiObelNx/cBuv/wzllvCCH3A=
github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ= github.com/matrix-org/pinecone v0.11.1-0.20230210171230-8c3b24f2649a/go.mod h1:HchJX9oKMXaT2xYFs0Ha/6Zs06mxLU8k6F1ODnrGkeQ=
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y= github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 h1:6z4KxomXSIGWqhHcfzExgkH3Z3UkIXry4ibJS4Aqz2Y=

View file

@ -149,7 +149,6 @@ func (r *Inviter) PerformInvite(
} }
input := gomatrixserverlib.PerformInviteInput{ input := gomatrixserverlib.PerformInviteInput{
Context: ctx,
RoomID: *validRoomID, RoomID: *validRoomID,
Event: event.PDU, Event: event.PDU,
InvitedUser: *invitedUser, InvitedUser: *invitedUser,
@ -158,7 +157,7 @@ func (r *Inviter) PerformInvite(
MembershipQuerier: &api.MembershipQuerier{Roomserver: r.RSAPI}, MembershipQuerier: &api.MembershipQuerier{Roomserver: r.RSAPI},
StateQuerier: &QueryState{r.DB}, StateQuerier: &QueryState{r.DB},
} }
inviteEvent, err := gomatrixserverlib.PerformInvite(input, r.FSAPI) inviteEvent, err := gomatrixserverlib.PerformInvite(ctx, input, r.FSAPI)
if err != nil { if err != nil {
switch e := err.(type) { switch e := err.(type) {
case spec.MatrixError: case spec.MatrixError: