diff options
Diffstat (limited to 'Firestore/Source/Model/FSTDocument.mm')
-rw-r--r-- | Firestore/Source/Model/FSTDocument.mm | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/Firestore/Source/Model/FSTDocument.mm b/Firestore/Source/Model/FSTDocument.mm index 9898c2a..8c4c801 100644 --- a/Firestore/Source/Model/FSTDocument.mm +++ b/Firestore/Source/Model/FSTDocument.mm @@ -18,37 +18,38 @@ #include <utility> -#import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Util/FSTAssert.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +#include "Firestore/core/src/firebase/firestore/util/hashing.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; using firebase::firestore::model::DocumentKey; using firebase::firestore::model::FieldPath; +using firebase::firestore::model::SnapshotVersion; NS_ASSUME_NONNULL_BEGIN @interface FSTMaybeDocument () - (instancetype)initWithKey:(DocumentKey)key - version:(FSTSnapshotVersion *)version NS_DESIGNATED_INITIALIZER; + version:(SnapshotVersion)version NS_DESIGNATED_INITIALIZER; @end @implementation FSTMaybeDocument { DocumentKey _key; + SnapshotVersion _version; } -- (instancetype)initWithKey:(DocumentKey)key version:(FSTSnapshotVersion *)version { - FSTAssert(!!version, @"Version must not be nil."); +- (instancetype)initWithKey:(DocumentKey)key version:(SnapshotVersion)version { self = [super init]; if (self) { _key = std::move(key); - _version = version; + _version = std::move(version); } return self; } @@ -62,25 +63,29 @@ NS_ASSUME_NONNULL_BEGIN return _key; } +- (const SnapshotVersion &)version { + return _version; +} + @end @implementation FSTDocument + (instancetype)documentWithData:(FSTObjectValue *)data key:(DocumentKey)key - version:(FSTSnapshotVersion *)version + version:(SnapshotVersion)version hasLocalMutations:(BOOL)mutations { return [[FSTDocument alloc] initWithData:data key:std::move(key) - version:version + version:std::move(version) hasLocalMutations:mutations]; } - (instancetype)initWithData:(FSTObjectValue *)data key:(DocumentKey)key - version:(FSTSnapshotVersion *)version + version:(SnapshotVersion)version hasLocalMutations:(BOOL)mutations { - self = [super initWithKey:std::move(key) version:version]; + self = [super initWithKey:std::move(key) version:std::move(version)]; if (self) { _data = data; _localMutations = mutations; @@ -97,21 +102,22 @@ NS_ASSUME_NONNULL_BEGIN } FSTDocument *otherDoc = other; - return [self.key isEqual:otherDoc.key] && [self.version isEqual:otherDoc.version] && + return [self.key isEqual:otherDoc.key] && self.version == otherDoc.version && [self.data isEqual:otherDoc.data] && self.hasLocalMutations == otherDoc.hasLocalMutations; } - (NSUInteger)hash { NSUInteger result = [self.key hash]; - result = result * 31 + [self.version hash]; + result = result * 31 + self.version.Hash(); result = result * 31 + [self.data hash]; result = result * 31 + (self.hasLocalMutations ? 1 : 0); return result; } - (NSString *)description { - return [NSString stringWithFormat:@"<FSTDocument: key:%s version:%@ localMutations:%@ data:%@>", - self.key.ToString().c_str(), self.version, + return [NSString stringWithFormat:@"<FSTDocument: key:%s version:%s localMutations:%@ data:%@>", + self.key.ToString().c_str(), + self.version.timestamp().ToString().c_str(), self.localMutations ? @"YES" : @"NO", self.data]; } @@ -123,8 +129,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTDeletedDocument -+ (instancetype)documentWithKey:(DocumentKey)key version:(FSTSnapshotVersion *)version { - return [[FSTDeletedDocument alloc] initWithKey:std::move(key) version:version]; ++ (instancetype)documentWithKey:(DocumentKey)key version:(SnapshotVersion)version { + return [[FSTDeletedDocument alloc] initWithKey:std::move(key) version:std::move(version)]; } - (BOOL)isEqual:(id)other { @@ -136,12 +142,12 @@ NS_ASSUME_NONNULL_BEGIN } FSTDocument *otherDoc = other; - return [self.key isEqual:otherDoc.key] && [self.version isEqual:otherDoc.version]; + return [self.key isEqual:otherDoc.key] && self.version == otherDoc.version; } - (NSUInteger)hash { NSUInteger result = [self.key hash]; - result = result * 31 + [self.version hash]; + result = result * 31 + self.version.Hash(); return result; } |