From f9f58803768a7cb124c171b7abf68b5aa2be1fab Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 30 Nov 2017 11:13:15 +0000 Subject: [PATCH] Add transaction id to roomserver output API --- .../dendrite/roomserver/api/output.go | 3 +++ .../dendrite/roomserver/input/events.go | 2 +- .../dendrite/roomserver/input/latest_events.go | 18 +++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/roomserver/api/output.go b/src/github.com/matrix-org/dendrite/roomserver/api/output.go index 6a5c924c..c09d5a1e 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/api/output.go +++ b/src/github.com/matrix-org/dendrite/roomserver/api/output.go @@ -107,6 +107,9 @@ type OutputNewRoomEvent struct { // We encode the server name that the event should be sent using here to // future proof the API for virtual hosting. SendAsServer string `json:"send_as_server"` + // The transaction ID of the send request if sent by a local user and one + // was specified + TransactionID *TransactionID `json:"transaction_id"` } // An OutputNewInviteEvent is written whenever an invite becomes active. diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/events.go b/src/github.com/matrix-org/dendrite/roomserver/input/events.go index 9032219e..91de6435 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/events.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/events.go @@ -129,7 +129,7 @@ func processRoomEvent( } // Update the extremities of the event graph for the room - return updateLatestEvents(ctx, db, ow, roomNID, stateAtEvent, event, input.SendAsServer) + return updateLatestEvents(ctx, db, ow, roomNID, stateAtEvent, event, input.SendAsServer, input.TransactionID) } func processInviteEvent( diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go b/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go index 5767daab..2b82bcba 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/latest_events.go @@ -50,6 +50,7 @@ func updateLatestEvents( stateAtEvent types.StateAtEvent, event gomatrixserverlib.Event, sendAsServer string, + transactionID *api.TransactionID, ) (err error) { updater, err := db.GetLatestEventsForUpdate(ctx, roomNID) if err != nil { @@ -61,6 +62,7 @@ func updateLatestEvents( u := latestEventsUpdater{ ctx: ctx, db: db, updater: updater, ow: ow, roomNID: roomNID, stateAtEvent: stateAtEvent, event: event, sendAsServer: sendAsServer, + transactionID: transactionID, } if err = u.doUpdateLatestEvents(); err != nil { return err @@ -75,13 +77,14 @@ func updateLatestEvents( // The state could be passed using function arguments, but it becomes impractical // when there are so many variables to pass around. type latestEventsUpdater struct { - ctx context.Context - db RoomEventDatabase - updater types.RoomRecentEventsUpdater - ow OutputRoomEventWriter - roomNID types.RoomNID - stateAtEvent types.StateAtEvent - event gomatrixserverlib.Event + ctx context.Context + db RoomEventDatabase + updater types.RoomRecentEventsUpdater + ow OutputRoomEventWriter + roomNID types.RoomNID + stateAtEvent types.StateAtEvent + event gomatrixserverlib.Event + transactionID *api.TransactionID // Which server to send this event as. sendAsServer string // The eventID of the event that was processed before this one. @@ -241,6 +244,7 @@ func (u *latestEventsUpdater) makeOutputNewRoomEvent() (*api.OutputEvent, error) Event: u.event, LastSentEventID: u.lastEventIDSent, LatestEventIDs: latestEventIDs, + TransactionID: u.transactionID, } var stateEventNIDs []types.EventNID