@@ -194,25 +194,25 @@ - (void)doDelete:(NSString *)key {
194
194
[self .driver writeUserMutation: FSTTestDeleteMutation (key)];
195
195
}
196
196
197
- - (void )doWatchAck : (NSArray <NSNumber *> *)ackedTargets snapshot : ( NSNumber *) watchSnapshot {
197
+ - (void )doWatchAck : (NSArray <NSNumber *> *)ackedTargets {
198
198
FSTWatchTargetChange *change =
199
199
[FSTWatchTargetChange changeWithState: FSTWatchTargetChangeStateAdded
200
200
targetIDs: ackedTargets
201
201
cause: nil ];
202
- [self .driver receiveWatchChange: change snapshotVersion: [ self parseVersion: watchSnapshot] ];
202
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: : None () ];
203
203
}
204
204
205
- - (void )doWatchCurrent : (NSArray <id> *)currentSpec snapshot : ( NSNumber *) watchSnapshot {
205
+ - (void )doWatchCurrent : (NSArray <id> *)currentSpec {
206
206
NSArray <NSNumber *> *currentTargets = currentSpec[0 ];
207
207
NSData *resumeToken = [currentSpec[1 ] dataUsingEncoding: NSUTF8StringEncoding];
208
208
FSTWatchTargetChange *change =
209
209
[FSTWatchTargetChange changeWithState: FSTWatchTargetChangeStateCurrent
210
210
targetIDs: currentTargets
211
211
resumeToken: resumeToken];
212
- [self .driver receiveWatchChange: change snapshotVersion: [ self parseVersion: watchSnapshot] ];
212
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: : None () ];
213
213
}
214
214
215
- - (void )doWatchRemove : (NSDictionary *)watchRemoveSpec snapshot : ( NSNumber *) watchSnapshot {
215
+ - (void )doWatchRemove : (NSDictionary *)watchRemoveSpec {
216
216
NSError *error = nil ;
217
217
NSDictionary *cause = watchRemoveSpec[@" cause" ];
218
218
if (cause) {
@@ -226,19 +226,16 @@ - (void)doWatchRemove:(NSDictionary *)watchRemoveSpec snapshot:(NSNumber *)watch
226
226
[FSTWatchTargetChange changeWithState: FSTWatchTargetChangeStateRemoved
227
227
targetIDs: watchRemoveSpec[@" targetIds" ]
228
228
cause: error];
229
- [self .driver receiveWatchChange: change snapshotVersion: [ self parseVersion: watchSnapshot] ];
229
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: : None () ];
230
230
// Unlike web, the FSTMockDatastore detects a watch removal with cause and will remove active
231
231
// targets
232
232
}
233
233
234
- - (void )doWatchEntity : (NSDictionary *)watchEntity snapshot : ( NSNumber *_Nullable) watchSnapshot {
234
+ - (void )doWatchEntity : (NSDictionary *)watchEntity {
235
235
if (watchEntity[@" docs" ]) {
236
236
HARD_ASSERT (!watchEntity[@" doc" ], " Exactly one of |doc| or |docs| needs to be set." );
237
- int count = 0 ;
238
237
NSArray *docs = watchEntity[@" docs" ];
239
238
for (NSDictionary *doc in docs) {
240
- count++;
241
- bool isLast = (count == docs.count );
242
239
NSMutableDictionary *watchSpec = [NSMutableDictionary dictionary ];
243
240
watchSpec[@" doc" ] = doc;
244
241
if (watchEntity[@" targets" ]) {
@@ -247,11 +244,7 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity snapshot:(NSNumber *_Nullable)
247
244
if (watchEntity[@" removedTargets" ]) {
248
245
watchSpec[@" removedTargets" ] = watchEntity[@" removedTargets" ];
249
246
}
250
- NSNumber *_Nullable version = nil ;
251
- if (isLast) {
252
- version = watchSnapshot;
253
- }
254
- [self doWatchEntity: watchSpec snapshot: version];
247
+ [self doWatchEntity: watchSpec];
255
248
}
256
249
} else if (watchEntity[@" doc" ]) {
257
250
NSArray *docSpec = watchEntity[@" doc" ];
@@ -270,21 +263,21 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity snapshot:(NSNumber *_Nullable)
270
263
removedTargetIDs: watchEntity[@" removedTargets" ]
271
264
documentKey: doc.key
272
265
document: doc];
273
- [self .driver receiveWatchChange: change snapshotVersion: [ self parseVersion: watchSnapshot] ];
266
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: : None () ];
274
267
} else if (watchEntity[@" key" ]) {
275
268
FSTDocumentKey *docKey = FSTTestDocKey (watchEntity[@" key" ]);
276
269
FSTWatchChange *change =
277
270
[[FSTDocumentWatchChange alloc ] initWithUpdatedTargetIDs: @[]
278
271
removedTargetIDs: watchEntity[@" removedTargets" ]
279
272
documentKey: docKey
280
273
document: nil ];
281
- [self .driver receiveWatchChange: change snapshotVersion: [ self parseVersion: watchSnapshot] ];
274
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: : None () ];
282
275
} else {
283
276
HARD_FAIL (" Either key, doc or docs must be set." );
284
277
}
285
278
}
286
279
287
- - (void )doWatchFilter : (NSArray *)watchFilter snapshot : ( NSNumber *_Nullable) watchSnapshot {
280
+ - (void )doWatchFilter : (NSArray *)watchFilter {
288
281
NSArray <NSNumber *> *targets = watchFilter[0 ];
289
282
HARD_ASSERT (targets.count == 1 , " ExistenceFilters currently support exactly one target only." );
290
283
@@ -294,15 +287,29 @@ - (void)doWatchFilter:(NSArray *)watchFilter snapshot:(NSNumber *_Nullable)watch
294
287
FSTExistenceFilter *filter = [FSTExistenceFilter filterWithCount: keyCount];
295
288
FSTExistenceFilterWatchChange *change =
296
289
[FSTExistenceFilterWatchChange changeWithFilter: filter targetID: targets[0 ].intValue];
297
- [self .driver receiveWatchChange: change snapshotVersion: [ self parseVersion: watchSnapshot] ];
290
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: : None () ];
298
291
}
299
292
300
- - (void )doWatchReset : (NSArray <NSNumber *> *)watchReset snapshot : ( NSNumber *_Nullable) watchSnapshot {
293
+ - (void )doWatchReset : (NSArray <NSNumber *> *)watchReset {
301
294
FSTWatchTargetChange *change =
302
295
[FSTWatchTargetChange changeWithState: FSTWatchTargetChangeStateReset
303
296
targetIDs: watchReset
304
297
cause: nil ];
305
- [self .driver receiveWatchChange: change snapshotVersion: [self parseVersion: watchSnapshot]];
298
+ [self .driver receiveWatchChange: change snapshotVersion:SnapshotVersion: :None ()];
299
+ }
300
+
301
+ - (void )doWatchSnapshot : (NSDictionary *)watchSnapshot {
302
+ // The client will only respond to watchSnapshots if they are on a target change with an empty
303
+ // set of target IDs.
304
+ NSArray <NSNumber *> *targetIDs =
305
+ watchSnapshot[@" targetIds" ] ? watchSnapshot[@" targetIds" ] : [NSArray array ];
306
+ NSData *resumeToken = [watchSnapshot[@" resumeToken" ] dataUsingEncoding: NSUTF8StringEncoding];
307
+ FSTWatchTargetChange *change =
308
+ [FSTWatchTargetChange changeWithState: FSTWatchTargetChangeStateNoChange
309
+ targetIDs: targetIDs
310
+ resumeToken: resumeToken];
311
+ [self .driver receiveWatchChange: change
312
+ snapshotVersion: [self parseVersion: watchSnapshot[@" version" ]]];
306
313
}
307
314
308
315
- (void )doWatchStreamClose : (NSDictionary *)closeSpec {
@@ -415,17 +422,19 @@ - (void)doStep:(NSDictionary *)step {
415
422
} else if (step[@" userDelete" ]) {
416
423
[self doDelete: step[@" userDelete" ]];
417
424
} else if (step[@" watchAck" ]) {
418
- [self doWatchAck: step[@" watchAck" ] snapshot: step[ @" watchSnapshot " ] ];
425
+ [self doWatchAck: step[@" watchAck" ]];
419
426
} else if (step[@" watchCurrent" ]) {
420
- [self doWatchCurrent: step[@" watchCurrent" ] snapshot: step[ @" watchSnapshot " ] ];
427
+ [self doWatchCurrent: step[@" watchCurrent" ]];
421
428
} else if (step[@" watchRemove" ]) {
422
- [self doWatchRemove: step[@" watchRemove" ] snapshot: step[ @" watchSnapshot " ] ];
429
+ [self doWatchRemove: step[@" watchRemove" ]];
423
430
} else if (step[@" watchEntity" ]) {
424
- [self doWatchEntity: step[@" watchEntity" ] snapshot: step[ @" watchSnapshot " ] ];
431
+ [self doWatchEntity: step[@" watchEntity" ]];
425
432
} else if (step[@" watchFilter" ]) {
426
- [self doWatchFilter: step[@" watchFilter" ] snapshot: step[ @" watchSnapshot " ] ];
433
+ [self doWatchFilter: step[@" watchFilter" ]];
427
434
} else if (step[@" watchReset" ]) {
428
- [self doWatchReset: step[@" watchReset" ] snapshot: step[@" watchSnapshot" ]];
435
+ [self doWatchReset: step[@" watchReset" ]];
436
+ } else if (step[@" watchSnapshot" ]) {
437
+ [self doWatchSnapshot: step[@" watchSnapshot" ]];
429
438
} else if (step[@" watchStreamClose" ]) {
430
439
[self doWatchStreamClose: step[@" watchStreamClose" ]];
431
440
} else if (step[@" watchProto" ]) {
0 commit comments