Skip to content

Commit 749a46f

Browse files
committed
Merge pull request #726 from ParsePlatform/nlutsenko.properties.user
Convert all private ivars of PFUser to properties.
2 parents 4173457 + 8fe8b59 commit 749a46f

File tree

7 files changed

+56
-58
lines changed

7 files changed

+56
-58
lines changed

Parse/Internal/User/AuthenticationProviders/Controller/PFUserAuthenticationController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ - (void)unregisterAuthenticationDelegateForAuthType:(NSString *)authType {
118118
return [[self.dataSource.currentUserController getCurrentUserAsyncWithOptions:0] continueWithSuccessBlock:^id(BFTask<PFUser *> *task) {
119119
PFUser *currentUser = task.result;
120120
if (currentUser && [PFAnonymousUtils isLinkedWithUser:currentUser]) {
121-
if (currentUser.isLazy) {
121+
if (currentUser._lazy) {
122122
BFTask *resolveLaziness = nil;
123123
NSDictionary *oldAnonymousData = nil;
124124
@synchronized(currentUser.lock) {

Parse/Internal/User/CurrentUserController/PFCurrentUserController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ - (BFTask *)_getCurrentUserAsyncWithOptions:(PFCurrentUserLoadingOptions)options
120120
return [[[[self _loadCurrentUserFromDiskAsync] continueWithSuccessBlock:^id(BFTask *task) {
121121
PFUser *user = task.result;
122122
// If the object was not yet saved, but is already linked with AnonymousUtils - it means it is lazy.
123-
// So mark it's state as `isLazy` and make it `dirty`
123+
// So mark it's state as `lazy` and make it `dirty`
124124
if (!user.objectId && [PFAnonymousUtils isLinkedWithUser:user]) {
125-
user.isLazy = YES;
125+
user._lazy = YES;
126126
[user _setDirty:YES];
127127
}
128128
return user;
@@ -158,7 +158,7 @@ - (BFTask *)_saveCurrentUserAsync:(PFUser *)user {
158158
}
159159
return [[task continueWithBlock:^id(BFTask *task) {
160160
@synchronized (user.lock) {
161-
[user setIsCurrentUser:YES];
161+
user._current = YES;
162162
[user synchronizeAllAuthData];
163163
}
164164
return [self _saveCurrentUserToDiskAsync:user];
@@ -246,7 +246,7 @@ - (BFTask *)_loadCurrentUserFromDiskAsync {
246246
}
247247
return [task continueWithSuccessBlock:^id(BFTask *task) {
248248
PFUser *user = task.result;
249-
[user setIsCurrentUser:YES];
249+
user._current = YES;
250250
return [[self _loadSensitiveUserDataAsync:user
251251
fromKeychainItemWithName:PFUserCurrentUserKeychainItemName] continueWithSuccessResult:user];
252252
}];

Parse/Internal/User/PFUserPrivate.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,17 @@ extern NSString *const PFUserCurrentUserKeychainItemName;
5151
@end
5252

5353
// Private Properties
54-
@interface PFUser () {
55-
BOOL isCurrentUser;
56-
NSMutableDictionary *authData;
57-
NSMutableSet *linkedServiceNames;
58-
BOOL isLazy;
59-
}
60-
61-
// This earmarks the user as being an "identity" user. This will make saves write through
62-
// to the currentUser singleton and disk object
63-
@property (nonatomic, assign) BOOL isCurrentUser;
64-
65-
@property (nonatomic, strong, readonly) NSMutableDictionary *authData;
66-
@property (nonatomic, strong, readonly) NSMutableSet *linkedServiceNames;
67-
@property (nonatomic, assign) BOOL isLazy;
54+
@interface PFUser ()
55+
56+
@property (nonatomic, strong, readonly) NSMutableDictionary<NSString *, id> *authData;
57+
@property (nonatomic, strong, readonly) NSMutableSet<NSString *> *linkedServiceNames;
58+
59+
/**
60+
This earmarks the user as being an "identity" user.
61+
This will make saves write through to the currentUser singleton and disk object
62+
*/
63+
@property (nonatomic, assign) BOOL _current;
64+
@property (nonatomic, assign) BOOL _lazy;
6865

6966
- (BOOL)_isAuthenticatedWithCurrentUser:(PFUser *)currentUser;
7067

Parse/PFACL.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ - (void)setUnresolvedReadAccess:(BOOL)allowed forUser:(PFUser *)user {
275275
- (void)setReadAccess:(BOOL)allowed forUser:(PFUser *)user {
276276
NSString *objectId = user.objectId;
277277
if (!objectId) {
278-
if (user.isLazy) {
278+
if (user._lazy) {
279279
[self setUnresolvedReadAccess:allowed forUser:user];
280280
return;
281281
}
@@ -301,7 +301,7 @@ - (void)setUnresolvedWriteAccess:(BOOL)allowed forUser:(PFUser *)user {
301301
- (void)setWriteAccess:(BOOL)allowed forUser:(PFUser *)user {
302302
NSString *objectId = user.objectId;
303303
if (!objectId) {
304-
if (user.isLazy) {
304+
if (user._lazy) {
305305
[self setUnresolvedWriteAccess:allowed forUser:user];
306306
return;
307307
}

Parse/PFObject.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUser:(PFUser *)
435435
// This has to happen separately from everything else because there [PFUser save]
436436
// is special-cased to work for lazy users, but new users can't be created by
437437
// PFMultiCommand's regular save.
438-
if (currentUser.isLazy && [current containsObject:currentUser]) {
438+
if (currentUser._lazy && [current containsObject:currentUser]) {
439439
task = [task continueAsyncWithSuccessBlock:^id(BFTask *task) {
440440
return [currentUser saveInBackground];
441441
}];
@@ -607,7 +607,7 @@ + (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object
607607
// Unfortunately, ACLs with lazy users still cannot be saved, because the ACL does
608608
// does not get updated after the user save completes.
609609
// TODO: (nlutsenko) Make the ACL update after the user is saved.
610-
if (currentUser.isLazy && [current containsObject:currentUser]) {
610+
if (currentUser._lazy && [current containsObject:currentUser]) {
611611
[enqueueTasks addObject:[currentUser _enqueueSaveEventuallyWithChildren:NO]];
612612
[finished addObject:currentUser];
613613
[current removeObject:currentUser];

Parse/PFUser.m

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ @implementation PFUser (Private)
7070

7171
- (void)setDefaultValues {
7272
[super setDefaultValues];
73-
self.isCurrentUser = NO;
73+
self._current = NO;
7474
}
7575

7676
- (BOOL)needsDefaultACL {
@@ -136,7 +136,7 @@ + (void)_assertValidInstanceClassName:(NSString *)className {
136136
// Checks the properties on the object before saving.
137137
- (void)_checkSaveParametersWithCurrentUser:(PFUser *)currentUser {
138138
@synchronized([self lock]) {
139-
PFConsistencyAssert(self.objectId || self.isLazy,
139+
PFConsistencyAssert(self.objectId || self._lazy,
140140
@"User cannot be saved unless they are already signed up. Call signUp first.");
141141

142142
PFConsistencyAssert([self _isAuthenticatedWithCurrentUser:currentUser] ||
@@ -181,7 +181,7 @@ - (NSMutableDictionary *)_convertToDictionaryForSaving:(PFOperationSet *)changes
181181

182182
- (BFTask *)handleSaveResultAsync:(NSDictionary *)result {
183183
return [[super handleSaveResultAsync:result] continueWithSuccessBlock:^id(BFTask *saveTask) {
184-
if (self.isCurrentUser) {
184+
if (self._current) {
185185
[self cleanUpAuthData];
186186
PFCurrentUserController *controller = [[self class] currentUserController];
187187
return [[controller saveCurrentObjectAsync:self] continueWithBlock:^id(BFTask *task) {
@@ -233,7 +233,7 @@ - (BFTask *)_handleServiceLoginCommandResult:(PFCommandResult *)result {
233233
}];
234234
}
235235
if (resultDictionary) {
236-
self.isLazy = NO;
236+
self._lazy = NO;
237237

238238
// Serialize the object to disk so we can later access it via currentUser
239239
PFCurrentUserController *controller = [[self class] currentUserController];
@@ -271,7 +271,7 @@ - (BFTask *)handleSignUpResultAsync:(BFTask *)task {
271271
state.sessionToken = result[PFUserSessionTokenRESTKey];
272272
state.isNew = YES;
273273
}];
274-
self.isLazy = NO;
274+
self._lazy = NO;
275275
}
276276
}
277277
return signUpTask;
@@ -380,7 +380,7 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
380380

381381
- (void)synchronizeAuthDataWithAuthType:(NSString *)authType {
382382
@synchronized([self lock]) {
383-
if (!self.isCurrentUser) {
383+
if (!self._current) {
384384
return;
385385
}
386386

@@ -407,13 +407,13 @@ - (void)synchronizeAllAuthData {
407407

408408
- (BFTask *)resolveLazinessAsync:(BFTask *)toAwait {
409409
@synchronized([self lock]) {
410-
if (!self.isLazy) {
410+
if (!self._lazy) {
411411
return [BFTask taskWithResult:self];
412412
}
413413
if (self.linkedServiceNames.count == 0) {
414414
// If there are no linked services, treat this like a sign-up.
415415
return [[self signUpAsync:toAwait] continueAsyncWithSuccessBlock:^id(BFTask *task) {
416-
self.isLazy = NO;
416+
self._lazy = NO;
417417
return self;
418418
}];
419419
}
@@ -458,8 +458,8 @@ - (BFTask *)_logOutAsyncWithAuthType:(NSString *)authType {
458458
+ (instancetype)logInLazyUserWithAuthType:(NSString *)authType authData:(NSDictionary *)authData {
459459
PFUser *user = [self user];
460460
@synchronized([user lock]) {
461-
[user setIsCurrentUser:YES];
462-
user.isLazy = YES;
461+
user._current = YES;
462+
user._lazy = YES;
463463
user.authData[authType] = authData;
464464
[user.linkedServiceNames addObject:authType];
465465
}
@@ -497,7 +497,7 @@ - (BFTask *)signUpAsync:(BFTask *)toAwait {
497497
// self doesn't have any outstanding saves, so we can safely merge its operations
498498
// into the current user.
499499

500-
PFConsistencyAssert(!isCurrentUser, @"Attempt to merge currentUser with itself.");
500+
PFConsistencyAssert(!self._current, @"Attempt to merge currentUser with itself.");
501501

502502
@synchronized ([currentUser lock]) {
503503
NSString *oldUsername = [currentUser.username copy];
@@ -603,7 +603,7 @@ - (PFRESTCommand *)_constructSaveCommandForChanges:(PFOperationSet *)changes
603603
objectEncoder:(PFEncoder *)encoder {
604604
// If we are curent user - use the latest available session token, as it might have been changed since
605605
// this command was enqueued.
606-
if (self.isCurrentUser) {
606+
if (self._current) {
607607
token = self.sessionToken;
608608
}
609609
return [super _constructSaveCommandForChanges:changes
@@ -770,9 +770,10 @@ @implementation PFUser
770770
@dynamic password;
771771

772772
// PFUser (Private):
773-
@dynamic authData;
774-
@dynamic linkedServiceNames;
775-
@dynamic isLazy;
773+
@synthesize authData = _authData;
774+
@synthesize linkedServiceNames = _linkedServiceNames;
775+
@synthesize _current = _current;
776+
@synthesize _lazy = _lazy;
776777

777778
+ (NSString *)parseClassName {
778779
return @"_User";
@@ -783,15 +784,15 @@ + (instancetype)currentUser {
783784
return [[controller getCurrentObjectAsync] waitForResult:nil withMainThreadWarning:NO];
784785
}
785786

786-
- (BOOL)isCurrentUser {
787+
- (BOOL)_current {
787788
@synchronized(self.lock) {
788-
return isCurrentUser;
789+
return _current;
789790
}
790791
}
791792

792-
- (void)setIsCurrentUser:(BOOL)aBool {
793+
- (void)set_current:(BOOL)current {
793794
@synchronized(self.lock) {
794-
isCurrentUser = aBool;
795+
_current = current;
795796
}
796797
}
797798

@@ -985,7 +986,7 @@ - (BFTask *)_logOutAsync {
985986
[tasks addObject:task];
986987
}];
987988

988-
self.isCurrentUser = NO;
989+
self._current = NO;
989990

990991
token = [self.sessionToken copy];
991992

@@ -1025,20 +1026,20 @@ - (void)removeObjectForKey:(NSString *)key {
10251026

10261027
- (NSMutableDictionary *)authData {
10271028
@synchronized([self lock]) {
1028-
if (!authData) {
1029-
authData = [[NSMutableDictionary alloc] init];
1029+
if (!_authData) {
1030+
_authData = [[NSMutableDictionary alloc] init];
10301031
}
10311032
}
1032-
return authData;
1033+
return _authData;
10331034
}
10341035

10351036
- (NSMutableSet *)linkedServiceNames {
10361037
@synchronized([self lock]) {
1037-
if (!linkedServiceNames) {
1038-
linkedServiceNames = [[NSMutableSet alloc] init];
1038+
if (!_linkedServiceNames) {
1039+
_linkedServiceNames = [[NSMutableSet alloc] init];
10391040
}
10401041
}
1041-
return linkedServiceNames;
1042+
return _linkedServiceNames;
10421043
}
10431044

10441045
+ (instancetype)user {
@@ -1054,7 +1055,7 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
10541055
// but not always. Using continueAsyncWithBlock unlocks from the taskQueue, and solves the proplem.
10551056
return [toAwait continueAsyncWithBlock:^id(BFTask *task) {
10561057
@synchronized ([self lock]) {
1057-
if (self.isLazy) {
1058+
if (self._lazy) {
10581059
return [[self resolveLazinessAsync:toAwait] continueAsyncWithSuccessBlock:^id(BFTask *task) {
10591060
return @(!!task.result);
10601061
}];
@@ -1066,12 +1067,12 @@ - (BFTask *)saveAsync:(BFTask *)toAwait {
10661067
}
10671068

10681069
- (BFTask *)fetchAsync:(BFTask *)toAwait {
1069-
if (self.isLazy) {
1070+
if (self._lazy) {
10701071
return [BFTask taskWithResult:@YES];
10711072
}
10721073

10731074
return [[super fetchAsync:toAwait] continueAsyncWithSuccessBlock:^id(BFTask *fetchAsyncTask) {
1074-
if (self.isCurrentUser) {
1075+
if (self._current) {
10751076
[self cleanUpAuthData];
10761077
PFCurrentUserController *controller = [[self class] currentUserController];
10771078
return [[controller saveCurrentObjectAsync:self] continueAsyncWithBlock:^id(BFTask *task) {
@@ -1083,14 +1084,14 @@ - (BFTask *)fetchAsync:(BFTask *)toAwait {
10831084
}
10841085

10851086
- (instancetype)fetch:(NSError **)error {
1086-
if (self.isLazy) {
1087+
if (self._lazy) {
10871088
return self;
10881089
}
10891090
return [super fetch:error];
10901091
}
10911092

10921093
- (void)fetchInBackgroundWithBlock:(PFObjectResultBlock)block {
1093-
if (self.isLazy) {
1094+
if (self._lazy) {
10941095
if (block) {
10951096
block(self, nil);
10961097
return;
@@ -1116,11 +1117,11 @@ - (BOOL)isAuthenticated {
11161117

11171118
- (BOOL)_isAuthenticatedWithCurrentUser:(PFUser *)currentUser {
11181119
@synchronized([self lock]) {
1119-
BOOL authenticated = self.isLazy || self.sessionToken;
1120+
BOOL authenticated = self._lazy || self.sessionToken;
11201121
if (!authenticated && currentUser != nil) {
11211122
authenticated = [self.objectId isEqualToString:currentUser.objectId];
11221123
} else {
1123-
authenticated = self.isCurrentUser;
1124+
authenticated = self._current;
11241125
}
11251126
return authenticated;
11261127
}
@@ -1140,7 +1141,7 @@ - (void)signUpInBackgroundWithBlock:(PFBooleanResultBlock)block {
11401141
// For anonymous users, there may be an objectId. Setting the userName
11411142
// will have removed the anonymous link and set the value in the authData
11421143
// object to [NSNull null], so we can just treat it like a save operation.
1143-
if (authData[PFAnonymousUserAuthenticationType] == [NSNull null]) {
1144+
if (self.authData[PFAnonymousUserAuthenticationType] == [NSNull null]) {
11441145
[self saveInBackgroundWithBlock:block];
11451146
return;
11461147
}

Tests/Unit/ACLTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ - (void)testLazyUser {
122122
OCMStub(lazyUser.objectId).andDo(^(NSInvocation *invocation) {
123123
[invocation setReturnValue:&userId];
124124
});
125-
OCMStub(lazyUser.isLazy).andReturn(YES);
125+
OCMStub(lazyUser._lazy).andReturn(YES);
126126

127127
__block void (^saveListener)(id, NSError *) = nil;
128128

0 commit comments

Comments
 (0)