From 4de2d80e4371e50419823961789424d40561f75a Mon Sep 17 00:00:00 2001 From: Gil Date: Sun, 15 Apr 2018 16:56:43 -0700 Subject: Replace `QueryListenOptions` with simple booleans (#1106) * Replace `QueryListenOptions` with simple booleans Instead of calling addSnapshotListener( options:QueryListenOptions.includeQueryMetadataChanges() .includeDocumentMetadataChanges()) call addSnapshotListener(includeMetadataChanges:true) Also change `QuerySnapshot.documentChanges()` into a method which optionally takes `includeMetadataChanges:true`. By default even when listening to a query with `inlcudeMetadataChanges:true` metadata-only document changes are suppressed because they're confusing. * Revert QuerySnapshot.documentChanges back to a property Add usage. --- Firestore/Source/API/FIRQuery.mm | 62 +++++++--------------------------------- 1 file changed, 10 insertions(+), 52 deletions(-) (limited to 'Firestore/Source/API/FIRQuery.mm') diff --git a/Firestore/Source/API/FIRQuery.mm b/Firestore/Source/API/FIRQuery.mm index 9cdc572..14dcaef 100644 --- a/Firestore/Source/API/FIRQuery.mm +++ b/Firestore/Source/API/FIRQuery.mm @@ -48,47 +48,6 @@ using firebase::firestore::model::ResourcePath; NS_ASSUME_NONNULL_BEGIN -@interface FIRQueryListenOptions () - -- (instancetype)initWithIncludeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges - includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges - NS_DESIGNATED_INITIALIZER; - -@end - -@implementation FIRQueryListenOptions - -+ (instancetype)options { - return [[FIRQueryListenOptions alloc] init]; -} - -- (instancetype)initWithIncludeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges - includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges { - if (self = [super init]) { - _includeQueryMetadataChanges = includeQueryMetadataChanges; - _includeDocumentMetadataChanges = includeDocumentMetadataChanges; - } - return self; -} - -- (instancetype)init { - return [self initWithIncludeQueryMetadataChanges:NO includeDocumentMetadataChanges:NO]; -} - -- (instancetype)includeQueryMetadataChanges:(BOOL)includeQueryMetadataChanges { - return [[FIRQueryListenOptions alloc] - initWithIncludeQueryMetadataChanges:includeQueryMetadataChanges - includeDocumentMetadataChanges:_includeDocumentMetadataChanges]; -} - -- (instancetype)includeDocumentMetadataChanges:(BOOL)includeDocumentMetadataChanges { - return [[FIRQueryListenOptions alloc] - initWithIncludeQueryMetadataChanges:_includeQueryMetadataChanges - includeDocumentMetadataChanges:includeDocumentMetadataChanges]; -} - -@end - @interface FIRQuery () @property(nonatomic, strong, readonly) FSTQuery *query; @end @@ -162,14 +121,14 @@ NS_ASSUME_NONNULL_BEGIN } - (id)addSnapshotListener:(FIRQuerySnapshotBlock)listener { - return [self addSnapshotListenerWithOptions:nil listener:listener]; + return [self addSnapshotListenerWithIncludeMetadataChanges:NO listener:listener]; } -- (id)addSnapshotListenerWithOptions: - (nullable FIRQueryListenOptions *)options - listener:(FIRQuerySnapshotBlock)listener { - return [self addSnapshotListenerInternalWithOptions:[self internalOptions:options] - listener:listener]; +- (id) +addSnapshotListenerWithIncludeMetadataChanges:(BOOL)includeMetadataChanges + listener:(FIRQuerySnapshotBlock)listener { + auto options = [self internalOptionsForIncludeMetadataChanges:includeMetadataChanges]; + return [self addSnapshotListenerInternalWithOptions:options listener:listener]; } - (id) @@ -629,11 +588,10 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions } /** Converts the public API options object to the internal options object. */ -- (FSTListenOptions *)internalOptions:(nullable FIRQueryListenOptions *)options { - return [[FSTListenOptions alloc] - initWithIncludeQueryMetadataChanges:options.includeQueryMetadataChanges - includeDocumentMetadataChanges:options.includeDocumentMetadataChanges - waitForSyncWhenOnline:NO]; +- (FSTListenOptions *)internalOptionsForIncludeMetadataChanges:(BOOL)includeMetadataChanges { + return [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:includeMetadataChanges + includeDocumentMetadataChanges:includeMetadataChanges + waitForSyncWhenOnline:NO]; } @end -- cgit v1.2.3