Skip to content

Commit

Permalink
firestore(ios): update further ios code
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Aug 6, 2024
1 parent 412c470 commit 7499dc1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ - (void)invalidate {
}
[weakSelf sendSnapshotError:firebaseApp listenerId:listenerId error:error];
} else {
[weakSelf sendSnapshotEvent:firebaseApp listenerId:listenerId snapshot:snapshot];
[weakSelf sendSnapshotEvent:firebaseApp databaseId:databaseId listenerId:listenerId snapshot:snapshot];
}
};

Expand Down Expand Up @@ -141,9 +141,10 @@ - (void)invalidate {
error:error];
} else {
NSString *appName = [RNFBSharedUtils getAppJavaScriptName:firebaseApp.name];
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName databaseId: databaseId];
NSDictionary *serialized =
[RNFBFirestoreSerialize documentSnapshotToDictionary:snapshot
appName:appName];
firestoreKey:firestoreKey];
resolve(serialized);
}
}];
Expand Down Expand Up @@ -269,11 +270,13 @@ - (void)invalidate {
}

- (void)sendSnapshotEvent:(FIRApp *)firApp
databaseId: (NSString *) databaseId
listenerId:(nonnull NSNumber *)listenerId
snapshot:(FIRDocumentSnapshot *)snapshot {
NSString *appName = [RNFBSharedUtils getAppJavaScriptName:firApp.name];
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName databaseId: databaseId];
NSDictionary *serialized = [RNFBFirestoreSerialize documentSnapshotToDictionary:snapshot
appName:appName];
firestoreKey:firestoreKey];
[[RNFBRCTEventEmitter shared]
sendEventWithName:RNFB_FIRESTORE_DOCUMENT_SYNC
body:@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
appName:(NSString *)appName;

+ (NSDictionary *)documentSnapshotToDictionary:(FIRDocumentSnapshot *)snapshot
appName:(NSString *)appName;
firestoreKey:(NSString *)appName;

+ (NSDictionary *)serializeDictionary:(NSDictionary *)dictionary;

Expand Down
8 changes: 4 additions & 4 deletions packages/firestore/ios/RNFBFirestore/RNFBFirestoreSerialize.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ + (NSDictionary *)querySnapshotToDictionary:(NSString *)source
// set documents
NSMutableArray *documents = [[NSMutableArray alloc] init];
for (FIRDocumentSnapshot *documentSnapshot in documentSnapshots) {
[documents addObject:[self documentSnapshotToDictionary:documentSnapshot appName:appName]];
[documents addObject:[self documentSnapshotToDictionary:documentSnapshot firestoreKey:appName]];
}
snapshotMap[KEY_DOCUMENTS] = documents;

Expand Down Expand Up @@ -156,7 +156,7 @@ + (NSDictionary *)documentChangeToDictionary:(FIRDocumentChange *)documentChange
}

changeMap[KEY_DOC_CHANGE_DOCUMENT] = [self documentSnapshotToDictionary:documentChange.document
appName:appName];
firestoreKey:appName];

// Note the Firestore C++ SDK here returns a maxed UInt that is != NSUIntegerMax, so we make one
// ourselves so we can convert to -1 for JS land
Expand All @@ -180,7 +180,7 @@ + (NSDictionary *)documentChangeToDictionary:(FIRDocumentChange *)documentChange

// Native DocumentSnapshot -> NSDictionary (for JS)
+ (NSDictionary *)documentSnapshotToDictionary:(FIRDocumentSnapshot *)snapshot
appName:(NSString *)appName {
firestoreKey:(NSString *)firestoreKey {
NSMutableArray *metadata = [[NSMutableArray alloc] init];
NSMutableDictionary *documentMap = [[NSMutableDictionary alloc] init];

Expand All @@ -194,7 +194,7 @@ + (NSDictionary *)documentSnapshotToDictionary:(FIRDocumentSnapshot *)snapshot

if (snapshot.exists) {
NSString *key =
[NSString stringWithFormat:@"%@_%@", FIRESTORE_SERVER_TIMESTAMP_BEHAVIOR, appName];
[NSString stringWithFormat:@"%@_%@", FIRESTORE_SERVER_TIMESTAMP_BEHAVIOR, firestoreKey];
NSString *behavior = [[RNFBPreferences shared] getStringValue:key defaultValue:@"none"];

FIRServerTimestampBehavior serverTimestampBehavior;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ - (void)invalidate {
[RNFBFirestoreCommon promiseRejectFirestoreException:reject error:error];
} else {
NSString *appName = [RNFBSharedUtils getAppJavaScriptName:firebaseApp.name];
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName databaseId: databaseId];
NSDictionary *snapshotDict = [RNFBFirestoreSerialize documentSnapshotToDictionary:snapshot
appName:appName];
firestoreKey:firestoreKey];
NSString *snapshotPath = snapshotDict[@"path"];

if (snapshotPath == nil) {
Expand Down

0 comments on commit 7499dc1

Please sign in to comment.