Fix linter issues

This commit is contained in:
Till Faelligen 2021-08-22 20:24:17 +02:00
parent 41017f41f4
commit 0973a4e346
5 changed files with 22 additions and 19 deletions

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -84,7 +84,6 @@ func (o *testEDUProducer) InputReceiptEvent(
return nil
}
func (t *testEDUProducer) InputPresence(
ctx context.Context,
request *eduAPI.InputPresenceRequest,