diff --git a/syncapi/internal/keychange.go b/syncapi/internal/keychange.go index 0272ffc06..66134d791 100644 --- a/syncapi/internal/keychange.go +++ b/syncapi/internal/keychange.go @@ -29,6 +29,20 @@ import ( const DeviceListLogName = "dl" +// DeviceOTKCounts adds one-time key counts to the /sync response +func DeviceOTKCounts(ctx context.Context, keyAPI keyapi.KeyInternalAPI, userID, deviceID string, res *types.Response) error { + var queryRes api.QueryOneTimeKeysResponse + keyAPI.QueryOneTimeKeys(ctx, &api.QueryOneTimeKeysRequest{ + UserID: userID, + DeviceID: deviceID, + }, &queryRes) + if queryRes.Error != nil { + return queryRes.Error + } + res.DeviceListsOTKCount = queryRes.Count.KeyCount + return nil +} + // DeviceListCatchup fills in the given response for the given user ID to bring it up-to-date with device lists. hasNew=true if the response // was filled in, else false if there are no new device list changes because there is nothing to catch up on. The response MUST // be already filled in with join/leave information. @@ -36,6 +50,7 @@ func DeviceListCatchup( ctx context.Context, keyAPI keyapi.KeyInternalAPI, stateAPI currentstateAPI.CurrentStateInternalAPI, userID string, res *types.Response, from, to types.StreamingToken, ) (hasNew bool, err error) { + // Track users who we didn't track before but now do by virtue of sharing a room with them, or not. newlyJoinedRooms := joinedRooms(res, userID) newlyLeftRooms := leftRooms(res) diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index b530b34d1..d49d8b074 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -225,6 +225,10 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.Strea if err != nil { return } + err = internal.DeviceOTKCounts(req.ctx, rp.keyAPI, req.device.UserID, req.device.ID, res) + if err != nil { + return + } // Before we return the sync response, make sure that we take action on // any send-to-device database updates or deletions that we need to do.