@@ -128,81 +128,6 @@ - (double)doubleValue {
128
128
129
129
@end
130
130
131
- #pragma mark - FSTServerTimestampValue
132
-
133
- @implementation FSTServerTimestampValue {
134
- Timestamp _localWriteTime;
135
- }
136
-
137
- + (instancetype )serverTimestampValueWithLocalWriteTime : (const Timestamp &)localWriteTime
138
- previousValue : (nullable FSTFieldValue *)previousValue {
139
- return [[FSTServerTimestampValue alloc ] initWithLocalWriteTime: localWriteTime
140
- previousValue: previousValue];
141
- }
142
-
143
- - (id )initWithLocalWriteTime : (const Timestamp &)localWriteTime
144
- previousValue : (nullable FSTFieldValue *)previousValue {
145
- self = [super init ];
146
- if (self) {
147
- _localWriteTime = localWriteTime;
148
- _previousValue = previousValue;
149
- }
150
- return self;
151
- }
152
-
153
- - (FieldValue::Type)type {
154
- return FieldValue::Type::ServerTimestamp;
155
- }
156
-
157
- - (FSTTypeOrder)typeOrder {
158
- return FSTTypeOrderTimestamp;
159
- }
160
-
161
- - (id )value {
162
- return [NSNull null ];
163
- }
164
-
165
- - (id )valueWithOptions : (const FieldValueOptions &)options {
166
- switch (options.server_timestamp_behavior ()) {
167
- case ServerTimestampBehavior::kNone :
168
- return [NSNull null ];
169
- case ServerTimestampBehavior::kEstimate :
170
- return [FieldValue::FromTimestamp (self .localWriteTime).Wrap () valueWithOptions: options];
171
- case ServerTimestampBehavior::kPrevious :
172
- return self.previousValue ? [self .previousValue valueWithOptions: options] : [NSNull null ];
173
- default :
174
- HARD_FAIL (" Unexpected server timestamp option: %s" , options.server_timestamp_behavior ());
175
- }
176
- }
177
-
178
- - (BOOL )isEqual : (id )other {
179
- return [other isKindOfClass: [FSTFieldValue class ]] &&
180
- ((FSTFieldValue *)other).type == FieldValue::Type::ServerTimestamp &&
181
- self.localWriteTime == ((FSTServerTimestampValue *)other).localWriteTime ;
182
- }
183
-
184
- - (NSUInteger )hash {
185
- return TimestampInternal::Hash (self.localWriteTime );
186
- }
187
-
188
- - (NSString *)description {
189
- return [NSString
190
- stringWithFormat: @" <ServerTimestamp localTime=%s >" , self .localWriteTime.ToString ().c_str ()];
191
- }
192
-
193
- - (NSComparisonResult )compare : (FSTFieldValue *)other {
194
- if (other.type == FieldValue::Type::ServerTimestamp) {
195
- return WrapCompare (self.localWriteTime , ((FSTServerTimestampValue *)other).localWriteTime );
196
- } else if (other.type == FieldValue::Type::Timestamp) {
197
- // Server timestamps come after all concrete timestamps.
198
- return NSOrderedDescending;
199
- } else {
200
- return [self defaultCompare: other];
201
- }
202
- }
203
-
204
- @end
205
-
206
131
#pragma mark - FSTReferenceValue
207
132
208
133
@interface FSTReferenceValue ()
@@ -617,20 +542,19 @@ - (BOOL)isEqual:(id)other {
617
542
- (id )value {
618
543
switch (self.internalValue .type ()) {
619
544
case FieldValue::Type::Null:
545
+ // NSDictionary disallows storing `nil` values. Use NSNull as an
546
+ // explicitly existing null value.
620
547
return [NSNull null ];
621
548
case FieldValue::Type::Boolean :
622
549
return self.internalValue .boolean_value () ? @YES : @NO ;
623
550
case FieldValue::Type::Integer:
624
551
return @(self.internalValue .integer_value ());
625
552
case FieldValue::Type::Double:
626
553
return @(self.internalValue .double_value ());
627
- case FieldValue::Type::Timestamp: {
628
- auto timestamp = self.internalValue .timestamp_value ();
629
- return [[FIRTimestamp alloc ] initWithSeconds: timestamp.seconds ()
630
- nanoseconds: timestamp.nanoseconds ()];
631
- }
554
+ case FieldValue::Type::Timestamp:
555
+ return MakeFIRTimestamp (self.internalValue .timestamp_value ());
632
556
case FieldValue::Type::ServerTimestamp:
633
- HARD_FAIL ( " TODO(rsgowman): implement " ) ;
557
+ return [ NSNull null ] ;
634
558
case FieldValue::Type::String:
635
559
return util::WrapNSString (self.internalValue .string_value ());
636
560
case FieldValue::Type::Blob:
@@ -655,6 +579,22 @@ - (id)valueWithOptions:(const model::FieldValueOptions &)options {
655
579
return [[self value ] dateValue ];
656
580
}
657
581
582
+ case FieldValue::Type::ServerTimestamp: {
583
+ const auto &sts = self.internalValue .server_timestamp_value ();
584
+ switch (options.server_timestamp_behavior ()) {
585
+ case ServerTimestampBehavior::kNone :
586
+ return [NSNull null ];
587
+ case ServerTimestampBehavior::kEstimate :
588
+ return
589
+ [FieldValue::FromTimestamp (sts.local_write_time ()).Wrap () valueWithOptions: options];
590
+ case ServerTimestampBehavior::kPrevious :
591
+ return sts.previous_value () ? [sts.previous_value () valueWithOptions: options]
592
+ : [NSNull null ];
593
+ default :
594
+ HARD_FAIL (" Unexpected server timestamp option: %s" , options.server_timestamp_behavior ());
595
+ }
596
+ }
597
+
658
598
default :
659
599
return [self value ];
660
600
}
@@ -669,14 +609,8 @@ - (NSComparisonResult)compare:(FSTFieldValue *)other {
669
609
// FSTDelegateValue handles (eg) booleans to ensure this case never occurs.
670
610
671
611
if (FieldValue::Comparable (self.type , other.type )) {
672
- if ([other isKindOfClass: [FSTServerTimestampValue class ]]) {
673
- HARD_ASSERT (self.type == FieldValue::Type::Timestamp);
674
- // Server timestamps come after all concrete timestamps.
675
- return NSOrderedAscending;
676
- } else {
677
- HARD_ASSERT ([other isKindOfClass: [FSTDelegateValue class ]]);
678
- return WrapCompare<FieldValue>(self.internalValue , ((FSTDelegateValue *)other).internalValue );
679
- }
612
+ HARD_ASSERT ([other isKindOfClass: [FSTDelegateValue class ]]);
613
+ return WrapCompare<FieldValue>(self.internalValue , ((FSTDelegateValue *)other).internalValue );
680
614
} else {
681
615
return [self defaultCompare: other];
682
616
}
0 commit comments