Pass full device into CompleteSync

This commit is contained in:
Neil Alexander 2020-05-27 16:13:09 +01:00
parent 06cbe32545
commit 369d44064f
4 changed files with 11 additions and 11 deletions

View file

@ -58,7 +58,7 @@ type Database interface {
// ID.
IncrementalSync(ctx context.Context, device authtypes.Device, fromPos, toPos types.StreamingToken, numRecentEventsPerRoom int, wantFullState bool) (*types.Response, error)
// CompleteSync returns a complete /sync API response for the given user.
CompleteSync(ctx context.Context, userID string, numRecentEventsPerRoom int) (*types.Response, error)
CompleteSync(ctx context.Context, device authtypes.Device, numRecentEventsPerRoom int) (*types.Response, error)
// GetAccountDataInRange returns all account data for a given user inserted or
// updated between two given positions
// Returns a map following the format data[roomID] = []dataTypes

View file

@ -666,10 +666,10 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
}
func (d *Database) CompleteSync(
ctx context.Context, userID string, numRecentEventsPerRoom int,
ctx context.Context, device authtypes.Device, numRecentEventsPerRoom int,
) (*types.Response, error) {
res, toPos, joinedRoomIDs, err := d.getResponseWithPDUsForCompleteSync(
ctx, userID, numRecentEventsPerRoom,
ctx, device.UserID, numRecentEventsPerRoom,
)
if err != nil {
return nil, err

View file

@ -181,7 +181,7 @@ func TestSyncResponse(t *testing.T) {
Name: "CompleteSync limited",
DoSync: func() (*types.Response, error) {
// limit set to 5
return db.CompleteSync(ctx, testUserIDA, 5)
return db.CompleteSync(ctx, testUserDeviceA, 5)
},
// want the last 5 events
WantTimeline: events[len(events)-5:],
@ -193,7 +193,7 @@ func TestSyncResponse(t *testing.T) {
{
Name: "CompleteSync",
DoSync: func() (*types.Response, error) {
return db.CompleteSync(ctx, testUserIDA, len(events)+1)
return db.CompleteSync(ctx, testUserDeviceA, len(events)+1)
},
WantTimeline: events,
// We want no state at all as that field in /sync is the delta between the token (beginning of time)

View file

@ -47,7 +47,6 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
var syncData *types.Response
// Extract values from request
userID := device.UserID
syncReq, err := newSyncRequest(req, *device)
if err != nil {
return util.JSONResponse{
@ -56,7 +55,8 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
}
}
logger := util.GetLogger(req.Context()).WithFields(log.Fields{
"userID": userID,
"userID": device.UserID,
"deviceID": device.ID,
"since": syncReq.since,
"timeout": syncReq.timeout,
"limit": syncReq.limit,
@ -136,7 +136,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.StreamingToken) (res *types.Response, err error) {
// TODO: handle ignored users
if req.since == nil {
res, err = rp.db.CompleteSync(req.ctx, req.device.UserID, req.limit)
res, err = rp.db.CompleteSync(req.ctx, req.device, req.limit)
} else {
res, err = rp.db.IncrementalSync(req.ctx, req.device, *req.since, latestPos, req.limit, req.wantFullState)
}