Fix profile avatar downloads.

pull/1/head
Matthew Chen 7 years ago
parent dfa082238e
commit 15921fa0b5

@ -912,25 +912,13 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
return; return;
} }
// If we're transitioning from (no avatar -> no avatar) or from (same avatar -> same avatar),
// don't bother updating the avatar.
BOOL canSkipAvatarUpdate = ((avatarUrlPath.length == 0 && userProfile.avatarUrlPath.length == 0
&& userProfile.avatarFileName.length == 0)
|| (avatarUrlPath.length > 0 && userProfile.avatarUrlPath.length > 0 &&
[avatarUrlPath isEqualToString:userProfile.avatarUrlPath] && userProfile.avatarFileName));
NSString *_Nullable profileName = NSString *_Nullable profileName =
[self decryptProfileNameData:profileNameEncrypted profileKey:userProfile.profileKey]; [self decryptProfileNameData:profileNameEncrypted profileKey:userProfile.profileKey];
if (canSkipAvatarUpdate) {
[userProfile updateWithProfileName:profileName dbConnection:self.dbConnection completion:nil];
} else {
[userProfile updateWithProfileName:profileName [userProfile updateWithProfileName:profileName
avatarUrlPath:avatarUrlPath avatarUrlPath:avatarUrlPath
avatarFileName:nil
dbConnection:self.dbConnection dbConnection:self.dbConnection
completion:nil]; completion:nil];
}
// If we're updating the profile that corresponds to our local number, // If we're updating the profile that corresponds to our local number,
// update the local profile as well. // update the local profile as well.

@ -41,10 +41,6 @@ extern NSString *const kLocalProfileUniqueId;
#pragma mark - Update With... Methods #pragma mark - Update With... Methods
- (void)updateWithProfileName:(nullable NSString *)profileName
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

@ -109,7 +109,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
BOOL didChange; BOOL didChange;
if (_avatarUrlPath == nil && avatarUrlPath == nil) { if (_avatarUrlPath == nil && avatarUrlPath == nil) {
didChange = NO; didChange = NO;
} else if (_avatarUrlPath != nil && avatarUrlPath != nil) { } else if (_avatarUrlPath != nil || avatarUrlPath != nil) {
didChange = YES; didChange = YES;
} else { } else {
didChange = [_avatarUrlPath isEqualToString:avatarUrlPath]; didChange = [_avatarUrlPath isEqualToString:avatarUrlPath];
@ -204,18 +204,6 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
}); });
} }
- (void)updateWithProfileName:(nullable NSString *)profileName
dbConnection:(YapDatabaseConnection *)dbConnection
completion:(nullable OWSUserProfileCompletion)completion
{
[self applyChanges:^(OWSUserProfile *userProfile) {
[userProfile setProfileName:[profileName ows_stripped]];
}
functionName:__PRETTY_FUNCTION__
dbConnection:dbConnection
completion: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

Loading…
Cancel
Save