Skip to content

Commit b7a243d

Browse files
authored
Merge 106a0e3 into 48a77e3
2 parents 48a77e3 + 106a0e3 commit b7a243d

28 files changed

+7138
-37
lines changed

Firestore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [feature] Enable snapshot listener option to retrieve data from local cache only. (#12370)
3+
14
# 10.22.0
25
- [fixed] Fix the flaky offline behaviour when using `arrayRemove` on `Map` object. (#12378)
36

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 22 additions & 0 deletions
Large diffs are not rendered by default.

Firestore/Example/Tests/SpecTests/FSTSpecTests.mm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "Firestore/core/src/bundle/bundle_reader.h"
4242
#include "Firestore/core/src/bundle/bundle_serializer.h"
4343
#include "Firestore/core/src/core/field_filter.h"
44+
#import "Firestore/core/src/core/listen_options.h"
4445
#include "Firestore/core/src/credentials/user.h"
4546
#include "Firestore/core/src/local/persistence.h"
4647
#include "Firestore/core/src/local/target_data.h"
@@ -79,10 +80,12 @@
7980
using firebase::firestore::Error;
8081
using firebase::firestore::google_firestore_v1_ArrayValue;
8182
using firebase::firestore::google_firestore_v1_Value;
83+
using firebase::firestore::api::ListenSource;
8284
using firebase::firestore::api::LoadBundleTask;
8385
using firebase::firestore::bundle::BundleReader;
8486
using firebase::firestore::bundle::BundleSerializer;
8587
using firebase::firestore::core::DocumentViewChange;
88+
using firebase::firestore::core::ListenOptions;
8689
using firebase::firestore::core::Query;
8790
using firebase::firestore::credentials::User;
8891
using firebase::firestore::local::Persistence;
@@ -385,11 +388,25 @@ - (DocumentViewChange)parseChange:(NSDictionary *)jsonDoc ofType:(DocumentViewCh
385388
return DocumentViewChange{std::move(doc), type};
386389
}
387390

391+
- (ListenOptions)parseOptions:(NSDictionary *)optionsSpec {
392+
ListenOptions options = ListenOptions::FromIncludeMetadataChanges(true);
393+
394+
if (optionsSpec != nil) {
395+
ListenSource source =
396+
[optionsSpec[@"source"] isEqual:@"cache"] ? ListenSource::Cache : ListenSource::Default;
397+
// include_metadata_changes are default to true in spec tests
398+
options = ListenOptions::FromOptions(true, source);
399+
}
400+
401+
return options;
402+
}
403+
388404
#pragma mark - Methods for doing the steps of the spec test.
389405

390406
- (void)doListen:(NSDictionary *)listenSpec {
391407
Query query = [self parseQuery:listenSpec[@"query"]];
392-
TargetId actualID = [self.driver addUserListenerWithQuery:std::move(query)];
408+
ListenOptions options = [self parseOptions:listenSpec[@"options"]];
409+
TargetId actualID = [self.driver addUserListenerWithQuery:std::move(query) options:options];
393410

394411
TargetId expectedID = [listenSpec[@"targetId"] intValue];
395412
XCTAssertEqual(actualID, expectedID, @"targetID assigned to listen");

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,10 @@ typedef std::
146146
* Resulting events are captured and made available via the capturedEventsSinceLastCall method.
147147
*
148148
* @param query A valid query to execute against the backend.
149+
* @param options A listen option to configure snapshot listener.
149150
* @return The target ID assigned by the system to track the query.
150151
*/
151-
- (model::TargetId)addUserListenerWithQuery:(core::Query)query;
152+
- (model::TargetId)addUserListenerWithQuery:(core::Query)query options:(core::ListenOptions)options;
152153

153154
/**
154155
* Removes a listener from the FSTSyncEngine as if the user had removed a listener corresponding

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,8 @@ - (FSTOutstandingWrite *)receiveWriteError:(int)errorCode
476476
return result;
477477
}
478478

479-
- (TargetId)addUserListenerWithQuery:(Query)query {
480-
// TODO(dimond): Allow customizing listen options in spec tests
479+
- (TargetId)addUserListenerWithQuery:(Query)query options:(ListenOptions)options {
481480
// TODO(dimond): Change spec tests to verify isFromCache on snapshots
482-
ListenOptions options = ListenOptions::FromIncludeMetadataChanges(true);
483481
auto listener = QueryListener::Create(
484482
query, options, [self, query](const StatusOr<ViewSnapshot> &maybe_snapshot) {
485483
FSTQueryEvent *event = [[FSTQueryEvent alloc] init];

0 commit comments

Comments
 (0)