Code cleanup

// FREEBIE
pull/1/head
sdkjfhsdkjhfsdlkjhfsdf 7 years ago
parent 14723f3e7f
commit 4e6816ec5e

@ -729,16 +729,15 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
return; return;
} }
[userProfile updateWithProfileName:nil [userProfile clearWithProfileKey:profileKey
profileKey:profileKey dbConnection:self.dbConnection
avatarUrlPath:nil completion:^{
avatarFileName:nil dispatch_async(dispatch_get_main_queue(), ^(void) {
dbConnection:self.dbConnection [ProfileFetcherJob runWithRecipientId:recipientId
completion:^{ networkManager:self.networkManager
[ProfileFetcherJob runWithRecipientId:recipientId ignoreThrottling:YES];
networkManager:self.networkManager });
ignoreThrottling:YES]; }];
}];
}); });
} }
@ -911,6 +910,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
OWSUserProfile *userProfile = OWSUserProfile *userProfile =
[OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]; [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection];
if (!userProfile.profileKey) { if (!userProfile.profileKey) {
return; return;
} }
@ -918,8 +918,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
NSString *_Nullable profileName = NSString *_Nullable profileName =
[self decryptProfileNameData:profileNameEncrypted profileKey:userProfile.profileKey]; [self decryptProfileNameData:profileNameEncrypted profileKey:userProfile.profileKey];
BOOL isAvatarSame = [self isNullableStringEqual:userProfile.avatarUrlPath toString:avatarUrlPath];
[userProfile updateWithProfileName:profileName [userProfile updateWithProfileName:profileName
avatarUrlPath:avatarUrlPath avatarUrlPath:avatarUrlPath
avatarFileName:userProfile.avatarFileName // use existing file name if already downloaded avatarFileName:userProfile.avatarFileName // use existing file name if already downloaded
@ -944,10 +942,8 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
completion:nil]; completion:nil];
} }
if (!isAvatarSame) { if (userProfile.avatarUrlPath.length > 0 && userProfile.avatarFileName.length == 0) {
if (avatarUrlPath) { [self downloadAvatarForUserProfile:userProfile];
[self downloadAvatarForUserProfile:userProfile];
}
} }
}); });
} }

@ -41,13 +41,6 @@ extern NSString *const kLocalProfileUniqueId;
#pragma mark - Update With... Methods #pragma mark - Update With... Methods
- (void)updateWithProfileName:(nullable NSString *)profileName
profileKey:(OWSAES256Key *)profileKey
avatarUrlPath:(nullable NSString *)avatarUrlPath
avatarFileName:(nullable NSString *)avatarFileName
dbConnection:(YapDatabaseConnection *)dbConnection
completion:(nullable OWSUserProfileCompletion)completion;
- (void)updateWithProfileName:(nullable NSString *)profileName - (void)updateWithProfileName:(nullable NSString *)profileName
avatarUrlPath:(nullable NSString *)avatarUrlPath avatarUrlPath:(nullable NSString *)avatarUrlPath
avatarFileName:(nullable NSString *)avatarFileName avatarFileName:(nullable NSString *)avatarFileName

@ -105,7 +105,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
dbConnection:(YapDatabaseConnection *)dbConnection dbConnection:(YapDatabaseConnection *)dbConnection
completion:(nullable OWSUserProfileCompletion)completion completion:(nullable OWSUserProfileCompletion)completion
{ {
id beforeSnapshot = self.dictionaryValue; NSDictionary *beforeSnapshot = self.dictionaryValue;
changeBlock(self); changeBlock(self);
@ -116,12 +116,19 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
if (latestInstance) { if (latestInstance) {
changeBlock(latestInstance); changeBlock(latestInstance);
id afterSnapshot = latestInstance.dictionaryValue; NSDictionary *afterSnapshot = latestInstance.dictionaryValue;
if ([beforeSnapshot isEqual:afterSnapshot]) { if ([beforeSnapshot isEqual:afterSnapshot]) {
DDLogVerbose( DDLogVerbose(
@"%@ Ignoring redundant update in %s: %@", self.logTag, functionName, self.debugDescription); @"%@ Ignoring redundant update in %s: %@", self.logTag, functionName, self.debugDescription);
didChange = NO; didChange = NO;
} else { } else {
NSString *_Nullable oldAvatarUrlPath = beforeSnapshot[@"avatarUrlPath"];
if (!latestInstance.avatarUrlPath || ![latestInstance.avatarUrlPath isEqual:oldAvatarUrlPath]) {
// If the avatarURL changed, the avatarFileName can't be valid.
// Clear it.
latestInstance.avatarFileName = nil;
}
[latestInstance saveWithTransaction:transaction]; [latestInstance saveWithTransaction:transaction];
} }
} else { } else {
@ -198,24 +205,6 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
completion:completion]; completion:completion];
} }
- (void)updateWithProfileName:(nullable NSString *)profileName
profileKey:(OWSAES256Key *)profileKey
avatarUrlPath:(nullable NSString *)avatarUrlPath
avatarFileName:(nullable NSString *)avatarFileName
dbConnection:(YapDatabaseConnection *)dbConnection
completion:(nullable OWSUserProfileCompletion)completion
{
[self applyChanges:^(OWSUserProfile *userProfile) {
[userProfile setProfileName:[profileName ows_stripped]];
[userProfile setProfileKey:profileKey];
[userProfile setAvatarUrlPath:avatarUrlPath];
[userProfile setAvatarFileName:avatarFileName];
}
functionName:__PRETTY_FUNCTION__
dbConnection:dbConnection
completion:completion];
}
- (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath - (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath
avatarFileName:(nullable NSString *)avatarFileName avatarFileName:(nullable NSString *)avatarFileName
dbConnection:(YapDatabaseConnection *)dbConnection dbConnection:(YapDatabaseConnection *)dbConnection

Loading…
Cancel
Save