Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 1dd75a05ff
commit 46d27cef30

@ -85,8 +85,8 @@ NSString *const kNSNotificationName_OtherUsersProfileDidChange = @"kNSNotificati
NSString *const kOWSProfileManager_UserWhitelistCollection = @"kOWSProfileManager_UserWhitelistCollection"; NSString *const kOWSProfileManager_UserWhitelistCollection = @"kOWSProfileManager_UserWhitelistCollection";
NSString *const kOWSProfileManager_GroupWhitelistCollection = @"kOWSProfileManager_GroupWhitelistCollection"; NSString *const kOWSProfileManager_GroupWhitelistCollection = @"kOWSProfileManager_GroupWhitelistCollection";
/// The max bytes for a user's profile name, encoded in UTF8. // The max bytes for a user's profile name, encoded in UTF8.
/// Before encrypting and submitting we NULL pad the name data to this length. // Before encrypting and submitting we NULL pad the name data to this length.
static const NSUInteger kOWSProfileManager_NameDataLength = 26; static const NSUInteger kOWSProfileManager_NameDataLength = 26;
const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
@ -96,18 +96,21 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, readonly) TSNetworkManager *networkManager; @property (nonatomic, readonly) TSNetworkManager *networkManager;
// These properties can be accessed on any thread, while synchronized on self. // This property can be accessed on any thread, while synchronized on self.
@property (atomic, nullable) UserProfile *localUserProfile; @property (atomic, nullable) UserProfile *localUserProfile;
// This property can be accessed on any thread, while synchronized on self.
@property (atomic, nullable) UIImage *localCachedAvatarImage; @property (atomic, nullable) UIImage *localCachedAvatarImage;
// These caches are lazy-populated. The single point of truth is the database. // These caches are lazy-populated. The single point of truth is the database.
// //
// These properties can be accessed on any thread, while synchronized on self. // This property can be accessed on any thread, while synchronized on self.
@property (atomic, readonly) NSMutableDictionary<NSString *, NSNumber *> *userProfileWhitelistCache; @property (atomic, readonly) NSMutableDictionary<NSString *, NSNumber *> *userProfileWhitelistCache;
// This property can be accessed on any thread, while synchronized on self.
@property (atomic, readonly) NSMutableDictionary<NSString *, NSNumber *> *groupProfileWhitelistCache; @property (atomic, readonly) NSMutableDictionary<NSString *, NSNumber *> *groupProfileWhitelistCache;
// These properties can be accessed on any thread, while synchronized on self. // This property can be accessed on any thread, while synchronized on self.
@property (atomic, readonly) NSCache<NSString *, UIImage *> *otherUsersProfileAvatarImageCache; @property (atomic, readonly) NSCache<NSString *, UIImage *> *otherUsersProfileAvatarImageCache;
// This property can be accessed on any thread, while synchronized on self.
@property (atomic, readonly) NSMutableSet<NSString *> *currentAvatarDownloads; @property (atomic, readonly) NSMutableSet<NSString *> *currentAvatarDownloads;
@end @end
@ -880,15 +883,15 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
{ {
[self.currentAvatarDownloads removeObject:userProfile.recipientId]; [self.currentAvatarDownloads removeObject:userProfile.recipientId];
UserProfile *currentUserProfile = UserProfile *latestUserProfile =
[self getOrBuildUserProfileForRecipientId:userProfile.recipientId]; [self getOrBuildUserProfileForRecipientId:userProfile.recipientId];
if (currentUserProfile.profileKey.keyData.length < 1 if (latestUserProfile.profileKey.keyData.length < 1
|| ![currentUserProfile.profileKey isEqual:userProfile.profileKey]) { || ![latestUserProfile.profileKey isEqual:userProfile.profileKey]) {
DDLogWarn(@"%@ Ignoring avatar download for obsolete user profile.", self.tag); DDLogWarn(@"%@ Ignoring avatar download for obsolete user profile.", self.tag);
} else if (![avatarUrlPathAtStart isEqualToString:currentUserProfile.avatarUrlPath]) { } else if (![avatarUrlPathAtStart isEqualToString:latestUserProfile.avatarUrlPath]) {
DDLogInfo(@"%@ avatar url has changed during download", self.tag); DDLogInfo(@"%@ avatar url has changed during download", self.tag);
if (currentUserProfile.avatarUrlPath.length > 0) { if (latestUserProfile.avatarUrlPath.length > 0) {
[self downloadAvatarForUserProfile:currentUserProfile]; [self downloadAvatarForUserProfile:latestUserProfile];
} }
} else if (error) { } else if (error) {
DDLogError(@"%@ avatar download failed: %@", self.tag, error); DDLogError(@"%@ avatar download failed: %@", self.tag, error);
@ -899,7 +902,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
} else if (!image) { } else if (!image) {
DDLogError(@"%@ avatar image could not be loaded: %@", self.tag, error); DDLogError(@"%@ avatar image could not be loaded: %@", self.tag, error);
} else { } else {
// TODO: Verify that the avatar URL hasn't changed since the download began.
[self.otherUsersProfileAvatarImageCache setObject:image forKey:userProfile.recipientId]; [self.otherUsersProfileAvatarImageCache setObject:image forKey:userProfile.recipientId];
userProfile.avatarFileName = fileName; userProfile.avatarFileName = fileName;

Loading…
Cancel
Save