Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Aug 6, 2024
1 parent bad8f09 commit adab55d
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ static FirebaseFirestore getFirestoreForApp(String appName, String databaseId) {
return instance;
}

private static void setFirestoreSettings(FirebaseFirestore firebaseFirestore, String firestoreKey) {
private static void setFirestoreSettings(
FirebaseFirestore firebaseFirestore, String firestoreKey) {

UniversalFirebasePreferences preferences = UniversalFirebasePreferences.getSharedInstance();
FirebaseFirestoreSettings.Builder firestoreSettings = new FirebaseFirestoreSettings.Builder();

String cacheSizeKey = UniversalFirebaseFirestoreStatics.FIRESTORE_CACHE_SIZE + "_" + firestoreKey;
String cacheSizeKey =
UniversalFirebaseFirestoreStatics.FIRESTORE_CACHE_SIZE + "_" + firestoreKey;
String hostKey = UniversalFirebaseFirestoreStatics.FIRESTORE_HOST + "_" + firestoreKey;
String persistenceKey = UniversalFirebaseFirestoreStatics.FIRESTORE_PERSISTENCE + "_" + firestoreKey;
String persistenceKey =
UniversalFirebaseFirestoreStatics.FIRESTORE_PERSISTENCE + "_" + firestoreKey;
String sslKey = UniversalFirebaseFirestoreStatics.FIRESTORE_SSL + "_" + firestoreKey;

int cacheSizeBytes =
Expand Down
126 changes: 68 additions & 58 deletions packages/firestore/ios/RNFBFirestore/RNFBFirestoreCollectionModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (void)invalidate {

RCT_EXPORT_METHOD(namedQueryOnSnapshot
: (FIRApp *)firebaseApp
: (NSString *) databaseId
: (NSString *)databaseId
: (NSString *)name
: (NSString *)type
: (NSArray *)filters
Expand All @@ -75,34 +75,35 @@ - (void)invalidate {
return;
}

FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp databaseId:databaseId];
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
databaseId:databaseId];
[firestore getQueryNamed:name
completion:^(FIRQuery *query) {
if (query == nil) {
[self sendSnapshotError:firebaseApp
databaseId:databaseId
listenerId:listenerId
error:nil];
return;
}

RNFBFirestoreQuery *firestoreQuery =
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
query:query
filters:filters
orders:orders
options:options];
[self handleQueryOnSnapshot:firebaseApp
databaseId:databaseId
firestoreQuery:firestoreQuery
listenerId:listenerId
listenerOptions:listenerOptions];
}];
completion:^(FIRQuery *query) {
if (query == nil) {
[self sendSnapshotError:firebaseApp
databaseId:databaseId
listenerId:listenerId
error:nil];
return;
}

RNFBFirestoreQuery *firestoreQuery =
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
query:query
filters:filters
orders:orders
options:options];
[self handleQueryOnSnapshot:firebaseApp
databaseId:databaseId
firestoreQuery:firestoreQuery
listenerId:listenerId
listenerOptions:listenerOptions];
}];
}

RCT_EXPORT_METHOD(collectionOnSnapshot
: (FIRApp *)firebaseApp
: (NSString *) databaseId
: (NSString *)databaseId
: (NSString *)path
: (NSString *)type
: (NSArray *)filters
Expand All @@ -114,7 +115,8 @@ - (void)invalidate {
return;
}

FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp databaseId:databaseId];
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
databaseId:databaseId];
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];

RNFBFirestoreQuery *firestoreQuery = [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
Expand All @@ -129,7 +131,10 @@ - (void)invalidate {
listenerOptions:listenerOptions];
}

RCT_EXPORT_METHOD(collectionOffSnapshot : (FIRApp *)firebaseApp: (NSString *) databaseId : (nonnull NSNumber *)listenerId) {
RCT_EXPORT_METHOD(collectionOffSnapshot
: (FIRApp *)firebaseApp
: (NSString *)databaseId
: (nonnull NSNumber *)listenerId) {
id<FIRListenerRegistration> listener = collectionSnapshotListeners[listenerId];
if (listener) {
[listener remove];
Expand All @@ -139,7 +144,7 @@ - (void)invalidate {

RCT_EXPORT_METHOD(namedQueryGet
: (FIRApp *)firebaseApp
: (NSString *) databaseId
: (NSString *)databaseId
: (NSString *)name
: (NSString *)type
: (NSArray *)filters
Expand All @@ -148,40 +153,41 @@ - (void)invalidate {
: (NSDictionary *)getOptions
: (RCTPromiseResolveBlock)resolve
: (RCTPromiseRejectBlock)reject) {
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp databaseId:databaseId];
[firestore
getQueryNamed:name
completion:^(FIRQuery *query) {
if (query == nil) {
return [RNFBFirestoreCommon promiseRejectFirestoreException:reject error:nil];
}

RNFBFirestoreQuery *firestoreQuery =
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
query:query
filters:filters
orders:orders
options:options];
FIRFirestoreSource source = [self getSource:getOptions];
[self handleQueryGet:firebaseApp
firestoreQuery:firestoreQuery
source:source
resolve:resolve
reject:reject];
}];
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
databaseId:databaseId];
[firestore getQueryNamed:name
completion:^(FIRQuery *query) {
if (query == nil) {
return [RNFBFirestoreCommon promiseRejectFirestoreException:reject error:nil];
}

RNFBFirestoreQuery *firestoreQuery =
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
query:query
filters:filters
orders:orders
options:options];
FIRFirestoreSource source = [self getSource:getOptions];
[self handleQueryGet:firebaseApp
firestoreQuery:firestoreQuery
source:source
resolve:resolve
reject:reject];
}];
}

RCT_EXPORT_METHOD(collectionCount
: (FIRApp *)firebaseApp
: (NSString *) databaseId
: (NSString *)databaseId
: (NSString *)path
: (NSString *)type
: (NSArray *)filters
: (NSArray *)orders
: (NSDictionary *)options
: (RCTPromiseResolveBlock)resolve
: (RCTPromiseRejectBlock)reject) {
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp databaseId:databaseId];
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
databaseId:databaseId];
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];
RNFBFirestoreQuery *firestoreQuery = [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
query:query
Expand Down Expand Up @@ -211,7 +217,7 @@ - (void)invalidate {

RCT_EXPORT_METHOD(collectionGet
: (FIRApp *)firebaseApp
: (NSString *) databaseId
: (NSString *)databaseId
: (NSString *)path
: (NSString *)type
: (NSArray *)filters
Expand All @@ -220,7 +226,8 @@ - (void)invalidate {
: (NSDictionary *)getOptions
: (RCTPromiseResolveBlock)resolve
: (RCTPromiseRejectBlock)reject) {
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp databaseId:databaseId];
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
databaseId:databaseId];
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];

RNFBFirestoreQuery *firestoreQuery = [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
Expand All @@ -237,7 +244,7 @@ - (void)invalidate {
}

- (void)handleQueryOnSnapshot:(FIRApp *)firebaseApp
databaseId: (NSString *) databaseId
databaseId:(NSString *)databaseId
firestoreQuery:(RNFBFirestoreQuery *)firestoreQuery
listenerId:(nonnull NSNumber *)listenerId
listenerOptions:(NSDictionary *)listenerOptions {
Expand All @@ -254,7 +261,10 @@ - (void)handleQueryOnSnapshot:(FIRApp *)firebaseApp
[listener remove];
[collectionSnapshotListeners removeObjectForKey:listenerId];
}
[weakSelf sendSnapshotError:firebaseApp databaseId:databaseId listenerId:listenerId error:error];
[weakSelf sendSnapshotError:firebaseApp
databaseId:databaseId
listenerId:listenerId
error:error];
} else {
[weakSelf sendSnapshotEvent:firebaseApp
databaseId:databaseId
Expand Down Expand Up @@ -294,7 +304,7 @@ - (void)handleQueryGet:(FIRApp *)firebaseApp
}

- (void)sendSnapshotEvent:(FIRApp *)firApp
databaseId: (NSString *) databaseId
databaseId:(NSString *)databaseId
listenerId:(nonnull NSNumber *)listenerId
snapshot:(FIRQuerySnapshot *)snapshot
includeMetadataChanges:(BOOL)includeMetadataChanges {
Expand All @@ -308,7 +318,7 @@ - (void)sendSnapshotEvent:(FIRApp *)firApp
sendEventWithName:RNFB_FIRESTORE_COLLECTION_SYNC
body:@{
@"appName" : [RNFBSharedUtils getAppJavaScriptName:firApp.name],
@"databaseId": databaseId,
@"databaseId" : databaseId,
@"listenerId" : listenerId,
@"body" : @{
@"snapshot" : serialized,
Expand All @@ -317,15 +327,15 @@ - (void)sendSnapshotEvent:(FIRApp *)firApp
}

- (void)sendSnapshotError:(FIRApp *)firApp
databaseId: (NSString *) databaseId
databaseId:(NSString *)databaseId
listenerId:(nonnull NSNumber *)listenerId
error:(NSError *)error {
NSArray *codeAndMessage = [RNFBFirestoreCommon getCodeAndMessage:error];
[[RNFBRCTEventEmitter shared]
sendEventWithName:RNFB_FIRESTORE_COLLECTION_SYNC
body:@{
@"appName" : [RNFBSharedUtils getAppJavaScriptName:firApp.name],
@"databaseId": databaseId,
@"databaseId" : databaseId,
@"listenerId" : listenerId,
@"body" : @{
@"error" : @{
Expand Down
4 changes: 3 additions & 1 deletion packages/firestore/ios/RNFBFirestore/RNFBFirestoreCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

+ (NSString *)createFirestoreKeyWithAppName:(NSString *)appName databaseId:(NSString *)databaseId;

+ (void)setFirestoreSettings:(FIRFirestore *)firestore appName:(NSString *)appName databaseId:(NSString *)databaseId;
+ (void)setFirestoreSettings:(FIRFirestore *)firestore
appName:(NSString *)appName
databaseId:(NSString *)databaseId;

+ (FIRDocumentReference *)getDocumentForFirestore:(FIRFirestore *)firestore path:(NSString *)path;

Expand Down
23 changes: 15 additions & 8 deletions packages/firestore/ios/RNFBFirestore/RNFBFirestoreCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
NSMutableDictionary *instanceCache;

@implementation RNFBFirestoreCommon
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)app databaseId:(NSString *) databaseId {
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)app databaseId:(NSString *)databaseId {
if (instanceCache == nil) {
instanceCache = [[NSMutableDictionary alloc] init];
}
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:[app name] databaseId: databaseId];
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:[app name]
databaseId:databaseId];
FIRFirestore *cachedInstance = instanceCache[firestoreKey];

if (cachedInstance) {
Expand All @@ -42,15 +43,17 @@ + (FIRFirestore *)getFirestoreForApp:(FIRApp *)app databaseId:(NSString *) datab

FIRFirestore *instance = [FIRFirestore firestoreForApp:app database:databaseId];

[self setFirestoreSettings:instance appName:[RNFBSharedUtils getAppJavaScriptName:app.name] databaseId:databaseId];
[self setFirestoreSettings:instance
appName:[RNFBSharedUtils getAppJavaScriptName:app.name]
databaseId:databaseId];

instanceCache[[app name]] = instance;

return instance;
}

+ (NSString *)createFirestoreKeyWithAppName:(NSString *)appName databaseId:(NSString *)databaseId {
return [NSString stringWithFormat:@"%@:%@", appName, databaseId];
return [NSString stringWithFormat:@"%@:%@", appName, databaseId];
}

+ (dispatch_queue_t)getFirestoreQueue {
Expand All @@ -63,13 +66,16 @@ + (dispatch_queue_t)getFirestoreQueue {
return firestoreQueue;
}

+ (void)setFirestoreSettings:(FIRFirestore *)firestore appName:(NSString *)appName databaseId:(NSString *)databaseId {
+ (void)setFirestoreSettings:(FIRFirestore *)firestore
appName:(NSString *)appName
databaseId:(NSString *)databaseId {
FIRFirestoreSettings *firestoreSettings = [[FIRFirestoreSettings alloc] init];
RNFBPreferences *preferences = [RNFBPreferences shared];

firestoreSettings.dispatchQueue = [self getFirestoreQueue];

NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName databaseId: databaseId];

NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName
databaseId:databaseId];

NSString *cacheKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_CACHE_SIZE, firestoreKey];
NSInteger size = [preferences getIntegerValue:cacheKey defaultValue:0];
Expand All @@ -86,7 +92,8 @@ + (void)setFirestoreSettings:(FIRFirestore *)firestore appName:(NSString *)appNa
firestoreSettings.host = [preferences getStringValue:hostKey
defaultValue:firestore.settings.host];

NSString *persistenceKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_PERSISTENCE, firestoreKey];
NSString *persistenceKey =
[NSString stringWithFormat:@"%@_%@", FIRESTORE_PERSISTENCE, firestoreKey];
firestoreSettings.persistenceEnabled =
(BOOL)[preferences getBooleanValue:persistenceKey
defaultValue:firestore.settings.persistenceEnabled];
Expand Down
Loading

0 comments on commit adab55d

Please sign in to comment.