aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/API
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Source/API')
-rw-r--r--Firestore/Source/API/FIRCollectionReference.mm7
-rw-r--r--Firestore/Source/API/FIRDocumentReference.mm23
-rw-r--r--Firestore/Source/API/FIRDocumentSnapshot.mm2
-rw-r--r--Firestore/Source/API/FIRQuery.mm9
4 files changed, 22 insertions, 19 deletions
diff --git a/Firestore/Source/API/FIRCollectionReference.mm b/Firestore/Source/API/FIRCollectionReference.mm
index cb7b61a..9560d13 100644
--- a/Firestore/Source/API/FIRCollectionReference.mm
+++ b/Firestore/Source/API/FIRCollectionReference.mm
@@ -101,8 +101,7 @@ NS_ASSUME_NONNULL_BEGIN
if (parentPath.empty()) {
return nil;
} else {
- FSTDocumentKey *key =
- [FSTDocumentKey keyWithPath:[FSTResourcePath resourcePathWithCPPResourcePath:parentPath]];
+ FSTDocumentKey *key = [FSTDocumentKey keyWithPath:parentPath];
return [FIRDocumentReference referenceWithKey:key firestore:self.firestore];
}
}
@@ -135,9 +134,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (FIRDocumentReference *)documentWithAutoID {
- const ResourcePath path = self.query.path.Append(CreateAutoId());
- FSTDocumentKey *key =
- [FSTDocumentKey keyWithPath:[FSTResourcePath resourcePathWithCPPResourcePath:path]];
+ FSTDocumentKey *key = [FSTDocumentKey keyWithPath:self.query.path.Append(CreateAutoId())];
return [FIRDocumentReference referenceWithKey:key firestore:self.firestore];
}
diff --git a/Firestore/Source/API/FIRDocumentReference.mm b/Firestore/Source/API/FIRDocumentReference.mm
index b1a5d49..cc14af5 100644
--- a/Firestore/Source/API/FIRDocumentReference.mm
+++ b/Firestore/Source/API/FIRDocumentReference.mm
@@ -39,6 +39,12 @@
#import "Firestore/Source/Util/FSTAsyncQueryListener.h"
#import "Firestore/Source/Util/FSTUsageValidation.h"
+#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
+#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+
+namespace util = firebase::firestore::util;
+using firebase::firestore::model::ResourcePath;
+
NS_ASSUME_NONNULL_BEGIN
#pragma mark - FIRDocumentListenOptions
@@ -93,7 +99,8 @@ NS_ASSUME_NONNULL_BEGIN
path.canonicalString, path.length);
}
return
- [FIRDocumentReference referenceWithKey:[FSTDocumentKey keyWithPath:path] firestore:firestore];
+ [FIRDocumentReference referenceWithKey:[FSTDocumentKey keyWithPath:[path toCPPResourcePath]]
+ firestore:firestore];
}
+ (instancetype)referenceWithKey:(FSTDocumentKey *)key firestore:(FIRFirestore *)firestore {
@@ -136,16 +143,17 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Public Methods
- (NSString *)documentID {
- return [self.key.path lastSegment];
+ return util::WrapNSString(self.key.path.last_segment());
}
- (FIRCollectionReference *)parent {
- FSTResourcePath *parentPath = [self.key.path pathByRemovingLastSegment];
- return [FIRCollectionReference referenceWithPath:parentPath firestore:self.firestore];
+ return [FIRCollectionReference
+ referenceWithPath:[FSTResourcePath resourcePathWithCPPResourcePath:self.key.path.PopLast()]
+ firestore:self.firestore];
}
- (NSString *)path {
- return [self.key.path canonicalString];
+ return util::WrapNSString(self.key.path.CanonicalString());
}
- (FIRCollectionReference *)collectionWithPath:(NSString *)collectionPath {
@@ -153,7 +161,8 @@ NS_ASSUME_NONNULL_BEGIN
FSTThrowInvalidArgument(@"Collection path cannot be nil.");
}
FSTResourcePath *subPath = [FSTResourcePath pathWithString:collectionPath];
- FSTResourcePath *path = [self.key.path pathByAppendingPath:subPath];
+ FSTResourcePath *path = [FSTResourcePath
+ resourcePathWithCPPResourcePath:self.key.path.Append([subPath toCPPResourcePath])];
return [FIRCollectionReference referenceWithPath:path firestore:self.firestore];
}
@@ -266,7 +275,7 @@ NS_ASSUME_NONNULL_BEGIN
addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
listener:(FIRDocumentSnapshotBlock)listener {
FIRFirestore *firestore = self.firestore;
- FSTQuery *query = [FSTQuery queryWithPath:[self.key.path toCPPResourcePath]];
+ FSTQuery *query = [FSTQuery queryWithPath:self.key.path];
FSTDocumentKey *key = self.key;
FSTViewSnapshotHandler snapshotHandler = ^(FSTViewSnapshot *snapshot, NSError *error) {
diff --git a/Firestore/Source/API/FIRDocumentSnapshot.mm b/Firestore/Source/API/FIRDocumentSnapshot.mm
index ddf4cca..8e731da 100644
--- a/Firestore/Source/API/FIRDocumentSnapshot.mm
+++ b/Firestore/Source/API/FIRDocumentSnapshot.mm
@@ -122,7 +122,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (NSString *)documentID {
- return [self.internalKey.path lastSegment];
+ return util::WrapNSString(self.internalKey.path.last_segment());
}
- (FIRSnapshotMetadata *)metadata {
diff --git a/Firestore/Source/API/FIRQuery.mm b/Firestore/Source/API/FIRQuery.mm
index 45ee482..c277561 100644
--- a/Firestore/Source/API/FIRQuery.mm
+++ b/Firestore/Source/API/FIRQuery.mm
@@ -469,8 +469,7 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
@"Invalid query. When querying by document ID you must provide "
"a valid document ID, but it was an empty string.");
}
- FSTResourcePath *path = [[FSTResourcePath resourcePathWithCPPResourcePath:self.query.path]
- pathByAppendingSegment:documentKey];
+ ResourcePath path = self.query.path.Append([documentKey UTF8String]);
fieldValue = [FSTReferenceValue referenceValue:[FSTDocumentKey keyWithPath:path]
databaseID:self.firestore.databaseID];
} else if ([value isKindOfClass:[FIRDocumentReference class]]) {
@@ -621,10 +620,8 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
FSTThrowInvalidUsage(@"InvalidQueryException",
@"Invalid query. Document ID '%@' contains a slash.", documentID);
}
- FSTDocumentKey *key = [FSTDocumentKey
- keyWithPath:[FSTResourcePath
- resourcePathWithCPPResourcePath:self.query.path.Append(
- [documentID UTF8String])]];
+ FSTDocumentKey *key =
+ [FSTDocumentKey keyWithPath:self.query.path.Append([documentID UTF8String])];
[components
addObject:[FSTReferenceValue referenceValue:key databaseID:self.firestore.databaseID]];
} else {