Use local profile data for the local phone number.

pull/1/head
Matthew Chen 7 years ago
parent 5e253f1c26
commit d9c8a218bc

@ -111,6 +111,12 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
object:nil]; object:nil];
} }
#pragma mark - Dependencies
- (TSAccountManager *)tsAccountManager {
return TSAccountManager.sharedInstance;
}
- (AFHTTPSessionManager *)avatarHTTPManager - (AFHTTPSessionManager *)avatarHTTPManager
{ {
return [OWSSignalService sharedInstance].CDNSessionManager; return [OWSSignalService sharedInstance].CDNSessionManager;
@ -491,7 +497,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
NSString *_Nullable localNumber = [TSAccountManager sharedInstance].localNumber; NSString *_Nullable localNumber = self.tsAccountManager.localNumber;
if (!localNumber) { if (!localNumber) {
return; return;
} }
@ -676,7 +682,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
- (void)logUserProfiles - (void)logUserProfiles
{ {
[self.dbConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.dbConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction) {
OWSLogError(@"logUserProfiles: %zd", [transaction numberOfKeysInCollection:OWSUserProfile.collection]); OWSLogError(@"logUserProfiles: %ld", (unsigned long) [transaction numberOfKeysInCollection:OWSUserProfile.collection]);
[transaction [transaction
enumerateKeysAndObjectsInCollection:OWSUserProfile.collection enumerateKeysAndObjectsInCollection:OWSUserProfile.collection
usingBlock:^(NSString *_Nonnull key, id _Nonnull object, BOOL *_Nonnull stop) { usingBlock:^(NSString *_Nonnull key, id _Nonnull object, BOOL *_Nonnull stop) {
@ -731,8 +737,10 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
OWSAssertDebug(recipientId.length > 0); OWSAssertDebug(recipientId.length > 0);
OWSUserProfile *userProfile = // For "local reads", use the local user profile.
[OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]; OWSUserProfile *userProfile = ([self.tsAccountManager.localNumber isEqualToString:recipientId]
? self.localUserProfile
: [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]);
OWSAssertDebug(userProfile); OWSAssertDebug(userProfile);
return userProfile.profileKey; return userProfile.profileKey;
@ -742,8 +750,10 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
OWSAssertDebug(recipientId.length > 0); OWSAssertDebug(recipientId.length > 0);
OWSUserProfile *userProfile = // For "local reads", use the local user profile.
[OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]; OWSUserProfile *userProfile = ([self.tsAccountManager.localNumber isEqualToString:recipientId]
? self.localUserProfile
: [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]);
return userProfile.profileName; return userProfile.profileName;
} }
@ -752,8 +762,10 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
OWSAssertDebug(recipientId.length > 0); OWSAssertDebug(recipientId.length > 0);
OWSUserProfile *userProfile = // For "local reads", use the local user profile.
[OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]; OWSUserProfile *userProfile = ([self.tsAccountManager.localNumber isEqualToString:recipientId]
? self.localUserProfile
: [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]);
if (userProfile.avatarFileName.length > 0) { if (userProfile.avatarFileName.length > 0) {
return [self loadProfileAvatarWithFilename:userProfile.avatarFileName]; return [self loadProfileAvatarWithFilename:userProfile.avatarFileName];
@ -770,8 +782,10 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
OWSAssertDebug(recipientId.length > 0); OWSAssertDebug(recipientId.length > 0);
OWSUserProfile *userProfile = // For "local reads", use the local user profile.
[OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]; OWSUserProfile *userProfile = ([self.tsAccountManager.localNumber isEqualToString:recipientId]
? self.localUserProfile
: [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId dbConnection:self.dbConnection]);
if (userProfile.avatarFileName.length > 0) { if (userProfile.avatarFileName.length > 0) {
return [self loadProfileDataWithFilename:userProfile.avatarFileName]; return [self loadProfileDataWithFilename:userProfile.avatarFileName];
@ -862,7 +876,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
// 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.
NSString *_Nullable localNumber = [TSAccountManager sharedInstance].localNumber; NSString *_Nullable localNumber = self.tsAccountManager.localNumber;
if (localNumber && [localNumber isEqualToString:userProfile.recipientId]) { if (localNumber && [localNumber isEqualToString:userProfile.recipientId]) {
OWSUserProfile *localUserProfile = self.localUserProfile; OWSUserProfile *localUserProfile = self.localUserProfile;
OWSAssertDebug(localUserProfile); OWSAssertDebug(localUserProfile);
@ -919,7 +933,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
// 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.
NSString *_Nullable localNumber = [TSAccountManager sharedInstance].localNumber; NSString *_Nullable localNumber = self.tsAccountManager.localNumber;
if (localNumber && [localNumber isEqualToString:recipientId]) { if (localNumber && [localNumber isEqualToString:recipientId]) {
OWSUserProfile *localUserProfile = self.localUserProfile; OWSUserProfile *localUserProfile = self.localUserProfile;
OWSAssertDebug(localUserProfile); OWSAssertDebug(localUserProfile);

Loading…
Cancel
Save