diff --git a/eduserver/api/input.go b/eduserver/api/input.go index 70bd4c3a6..cff1be9bc 100644 --- a/eduserver/api/input.go +++ b/eduserver/api/input.go @@ -118,9 +118,9 @@ type EDUServerInputAPI interface { InputPresence( ctx context.Context, request *InputPresenceRequest, - response *InputPresenceResponse, - ) error - + response *InputPresenceResponse, + ) error + InputCrossSigningKeyUpdate( ctx context.Context, request *InputCrossSigningKeyUpdateRequest, diff --git a/eduserver/input/input.go b/eduserver/input/input.go index f276fe51b..d8a3049d6 100644 --- a/eduserver/input/input.go +++ b/eduserver/input/input.go @@ -40,7 +40,7 @@ type EDUServerInputAPI struct { OutputSendToDeviceEventTopic string // The kafka topic to output new receipt events to OutputReceiptEventTopic string - // The kafka topic to output presence changes to + // The kafka topic to output presence changes to OutputPresenceTopic string // The kafka topic to output new key change events to OutputKeyChangeEventTopic string diff --git a/eduserver/inthttp/server.go b/eduserver/inthttp/server.go index b1310d129..c5ecebd1c 100644 --- a/eduserver/inthttp/server.go +++ b/eduserver/inthttp/server.go @@ -59,11 +59,11 @@ func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) { return util.MessageResponse(http.StatusBadRequest, err.Error()) } if err := t.InputPresence(req.Context(), &request, &response); err != nil { - return util.ErrorResponse(err) + return util.ErrorResponse(err) } return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), - ) + ) internalAPIMux.Handle(EDUServerInputCrossSigningKeyUpdatePath, httputil.MakeInternalAPI("inputCrossSigningKeyUpdate", func(req *http.Request) util.JSONResponse { var request api.InputCrossSigningKeyUpdateRequest diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 17086512c..056ce05c9 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -508,18 +508,7 @@ func (t *txnReq) processEDUs(ctx context.Context) { } } case gomatrixserverlib.MPresence: - now := time.Now() - payload := eduserverAPI.FederationPresenceData{} - if err := json.Unmarshal(e.Content, &payload); err != nil { - util.GetLogger(ctx).WithError(err).Error("Failed to unmarshal presence event") - continue - } - for _, presence := range payload.Push { - timestamp := gomatrixserverlib.AsTimestamp(now.Add(-(time.Millisecond * time.Duration(presence.LastActiveAgo)))) - if err := eduserverAPI.SetPresence(ctx, t.eduAPI, t.userAPI, presence.UserID, presence.StatusMsg, types.ToPresenceStatus(presence.Presence), timestamp); err != nil { - util.GetLogger(ctx).WithError(err).Error("unable to send presence data to edu server") - } - } + t.handlePresence(ctx, e) case eduserverAPI.MSigningKeyUpdate: var updatePayload eduserverAPI.CrossSigningKeyUpdate if err := json.Unmarshal(e.Content, &updatePayload); err != nil { @@ -542,6 +531,21 @@ func (t *txnReq) processEDUs(ctx context.Context) { } } +func (t *txnReq) handlePresence(ctx context.Context, e gomatrixserverlib.EDU) { + now := time.Now() + payload := eduserverAPI.FederationPresenceData{} + if err := json.Unmarshal(e.Content, &payload); err != nil { + util.GetLogger(ctx).WithError(err).Error("Failed to unmarshal presence event") + return + } + for _, presence := range payload.Push { + timestamp := gomatrixserverlib.AsTimestamp(now.Add(-(time.Millisecond * time.Duration(presence.LastActiveAgo)))) + if err := eduserverAPI.SetPresence(ctx, t.eduAPI, t.userAPI, presence.UserID, presence.StatusMsg, types.ToPresenceStatus(presence.Presence), timestamp); err != nil { + util.GetLogger(ctx).WithError(err).Error("unable to send presence data to edu server") + } + } +} + // processReceiptEvent sends receipt events to the edu server func (t *txnReq) processReceiptEvent(ctx context.Context, userID, roomID, receiptType string, diff --git a/federationapi/routing/send_test.go b/federationapi/routing/send_test.go index 87eaa3efc..041855704 100644 --- a/federationapi/routing/send_test.go +++ b/federationapi/routing/send_test.go @@ -84,7 +84,6 @@ func (o *testEDUProducer) InputReceiptEvent( return nil } - func (t *testEDUProducer) InputPresence( ctx context.Context, request *eduAPI.InputPresenceRequest,