FSTUser.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Auth/FSTUser.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. #pragma mark - FSTUser
  19. @implementation FSTUser
  20. @dynamic unauthenticated;
  21. + (instancetype)unauthenticatedUser {
  22. return [[FSTUser alloc] initWithUID:nil];
  23. }
  24. - (instancetype)initWithUID:(NSString *_Nullable)UID {
  25. if (self = [super init]) {
  26. _UID = UID;
  27. }
  28. return self;
  29. }
  30. - (BOOL)isEqual:(id)object {
  31. if (self == object) {
  32. return YES;
  33. } else if (![object isKindOfClass:[FSTUser class]]) {
  34. return NO;
  35. } else {
  36. FSTUser *other = object;
  37. return (self.isUnauthenticated && other.isUnauthenticated) ||
  38. [self.UID isEqualToString:other.UID];
  39. }
  40. }
  41. - (NSUInteger)hash {
  42. return [self.UID hash];
  43. }
  44. - (id)copyWithZone:(nullable NSZone *)zone {
  45. return self; // since FSTUser objects are immutable
  46. }
  47. - (NSString *)description {
  48. return [NSString stringWithFormat:@"<FSTUser uid=%@>", self.UID];
  49. }
  50. - (BOOL)isUnauthenticated {
  51. return self.UID == nil;
  52. }
  53. @end
  54. NS_ASSUME_NONNULL_END