Re-sync local profile state with service if necessary.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-08-29 13:07:34 -04:00
parent cf7f9dabfe
commit 71d7490e35
3 changed files with 45 additions and 0 deletions

View File

@ -785,6 +785,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// If there were any messages in our local queue which we hadn't yet processed.
[[OWSMessageReceiver sharedInstance] handleAnyUnprocessedEnvelopesAsync];
[OWSProfileManager.sharedManager syncLocalProfile];
}
- (void)ensureRootViewController

View File

@ -48,6 +48,10 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
- (BOOL)isProfileNameTooLong:(nullable NSString *)profileName;
// The local profile state can fall out of sync with the service
// (e.g. due to a botched profile update, for example).
- (void)syncLocalProfile;
#pragma mark - Profile Whitelist
#ifdef DEBUG

View File

@ -12,6 +12,7 @@
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSRequestBuilder.h>
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSProfileAvatarUploadFormRequest.h>
#import <SignalServiceKit/TSStorageManager.h>
@ -673,6 +674,17 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
});
}
- (void)syncLocalProfile
{
OWSAssert([NSThread isMainThread]);
NSString *_Nullable localNumber = [TSAccountManager sharedInstance].localNumber;
if (!localNumber) {
return;
}
[ProfileFetcherJob runWithRecipientId:localNumber networkManager:self.networkManager ignoreThrottling:YES];
}
#pragma mark - Profile Whitelist
#ifdef DEBUG
@ -1083,6 +1095,17 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
[self saveUserProfile:userProfile];
}
// If we're updating the profile that corresponds to our local number,
// update the local profile as well.
NSString *_Nullable localNumber = [TSAccountManager sharedInstance].localNumber;
if (localNumber && [localNumber isEqualToString:userProfile.recipientId]) {
UserProfile *localUserProfile = self.localUserProfile;
OWSAssert(localUserProfile);
localUserProfile.avatarFileName = fileName;
[self saveUserProfile:localUserProfile];
self.localCachedAvatarImage = image;
}
}
});
}];
@ -1160,6 +1183,22 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
userProfile.avatarUrlPath = avatarUrlPath;
userProfile.avatarFileName = nil;
// If we're updating the profile that corresponds to our local number,
// update the local profile as well.
NSString *_Nullable localNumber = [TSAccountManager sharedInstance].localNumber;
if (localNumber && [localNumber isEqualToString:recipientId]) {
UserProfile *localUserProfile = self.localUserProfile;
OWSAssert(localUserProfile);
localUserProfile.profileName = profileName;
localUserProfile.avatarUrlPath = avatarUrlPath;
// Don't clear avatarFileName and localCachedAvatarImage optimistically.
// * The profile avatar probably isn't out of sync.
// * If the profile avatar is out of sync, it can be synced on next app launch.
// * We don't want to touch local avatar state until we've
// downloaded the latest avatar by downloadAvatarForUserProfile.
[self saveUserProfile:localUserProfile];
}
if (!isAvatarSame) {
// Evacuate avatar image cache.
[self.otherUsersProfileAvatarImageCache removeObjectForKey:recipientId];