17
17
#import " FIRDocumentChange.h"
18
18
19
19
#import " Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
20
+ #import " Firestore/Source/API/FIRFirestore+Internal.h"
20
21
#import " Firestore/Source/Core/FSTQuery.h"
21
22
#import " Firestore/Source/Model/FSTDocument.h"
22
23
#import " Firestore/Source/Model/FSTDocumentSet.h"
23
24
24
25
#include " Firestore/core/src/firebase/firestore/core/view_snapshot.h"
25
26
#include " Firestore/core/src/firebase/firestore/util/hard_assert.h"
26
27
28
+ using firebase::firestore::api::Firestore;
27
29
using firebase::firestore::core::DocumentViewChange;
28
30
using firebase::firestore::core::ViewSnapshot;
29
31
@@ -55,21 +57,21 @@ + (FIRDocumentChangeType)documentChangeTypeForChange:(const DocumentViewChange &
55
57
}
56
58
57
59
+ (NSArray <FIRDocumentChange *> *)documentChangesForSnapshot : (const ViewSnapshot &)snapshot
58
- includeMetadataChanges : (BOOL )includeMetadataChanges
59
- firestore : (FIRFirestore *)firestore {
60
+ includeMetadataChanges : (bool )includeMetadataChanges
61
+ firestore : (Firestore *)firestore {
60
62
if (snapshot.old_documents ().isEmpty ) {
61
63
// Special case the first snapshot because index calculation is easy and fast. Also all changes
62
64
// on the first snapshot are adds so there are also no metadata-only changes to filter out.
63
65
FSTDocument *_Nullable lastDocument = nil ;
64
66
NSUInteger index = 0 ;
65
67
NSMutableArray <FIRDocumentChange *> *changes = [NSMutableArray array ];
66
68
for (const DocumentViewChange &change : snapshot.document_changes ()) {
67
- FIRQueryDocumentSnapshot *document = [FIRQueryDocumentSnapshot
68
- snapshotWithFirestore : firestore
69
- documentKey: change.document ().key
70
- document: change.document ()
71
- fromCache: snapshot.from_cache ()
72
- hasPendingWrites: snapshot.mutated_keys ().contains (change.document ().key)];
69
+ FIRQueryDocumentSnapshot *document = [[ FIRQueryDocumentSnapshot alloc ]
70
+ initWithFirestore : firestore
71
+ documentKey: change.document ().key
72
+ document: change.document ()
73
+ fromCache: snapshot.from_cache ()
74
+ hasPendingWrites: snapshot.mutated_keys ().contains (change.document ().key)];
73
75
HARD_ASSERT (change.type () == DocumentViewChange::Type::kAdded ,
74
76
" Invalid event type for first snapshot" );
75
77
HARD_ASSERT (!lastDocument || snapshot.query ().comparator (lastDocument, change.document ()) ==
@@ -91,12 +93,12 @@ + (FIRDocumentChangeType)documentChangeTypeForChange:(const DocumentViewChange &
91
93
continue ;
92
94
}
93
95
94
- FIRQueryDocumentSnapshot *document = [FIRQueryDocumentSnapshot
95
- snapshotWithFirestore : firestore
96
- documentKey: change.document ().key
97
- document: change.document ()
98
- fromCache: snapshot.from_cache ()
99
- hasPendingWrites: snapshot.mutated_keys ().contains (change.document ().key)];
96
+ FIRQueryDocumentSnapshot *document = [[ FIRQueryDocumentSnapshot alloc ]
97
+ initWithFirestore : firestore
98
+ documentKey: change.document ().key
99
+ document: change.document ()
100
+ fromCache: snapshot.from_cache ()
101
+ hasPendingWrites: snapshot.mutated_keys ().contains (change.document ().key)];
100
102
101
103
NSUInteger oldIndex = NSNotFound ;
102
104
NSUInteger newIndex = NSNotFound ;
0 commit comments