diff --git a/SignalMessaging/profiles/OWSProfileManager.h b/SignalMessaging/profiles/OWSProfileManager.h index 149439bba..f252f44ab 100644 --- a/SignalMessaging/profiles/OWSProfileManager.h +++ b/SignalMessaging/profiles/OWSProfileManager.h @@ -32,7 +32,7 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; - (OWSAES256Key *)localProfileKey; // localUserProfileExists is true if there is _ANY_ local profile. - (BOOL)localProfileExists; -// localUserProfileExists is true if there is a local profile with a name or avatar. +// hasLocalProfile is true if there is a local profile with a name or avatar. - (BOOL)hasLocalProfile; - (nullable NSString *)localProfileName; - (nullable UIImage *)localProfileAvatarImage; diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 4f4e54e12..07c633bcd 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -54,7 +54,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; @property (atomic, readonly) OWSUserProfile *localUserProfile; // This property can be accessed on any thread, while synchronized on self. -//@property (atomic, readonly) NSCache *otherUsersProfileAvatarImageCache; @property (atomic, readonly) NSCache *profileAvatarImageCache; // This property can be accessed on any thread, while synchronized on self. @@ -595,7 +594,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; OWSAssert(recipientId.length > 0); __block BOOL result = NO; - [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { NSNumber *_Nullable oldValue = [transaction objectForKey:recipientId inCollection:kOWSProfileManager_UserWhitelistCollection]; result = (oldValue && oldValue.boolValue); @@ -661,7 +660,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; NSString *groupIdKey = [groupId hexadecimalString]; __block BOOL result = NO; - [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { NSNumber *_Nullable oldValue = [transaction objectForKey:groupIdKey inCollection:kOWSProfileManager_GroupWhitelistCollection]; result = (oldValue && oldValue.boolValue); diff --git a/SignalMessaging/profiles/OWSUserProfile.h b/SignalMessaging/profiles/OWSUserProfile.h index 804482d74..0f9b5715b 100644 --- a/SignalMessaging/profiles/OWSUserProfile.h +++ b/SignalMessaging/profiles/OWSUserProfile.h @@ -20,6 +20,9 @@ extern NSString *const kNSNotificationKey_ProfileGroupId; extern NSString *const kLocalProfileUniqueId; // This class should be completely thread-safe. +// +// It is critical for coherency that all DB operations for this +// class should be done on OWSProfileManager's dbConnection. @interface OWSUserProfile : TSYapDatabaseObject @property (atomic, readonly) NSString *recipientId; diff --git a/SignalMessaging/profiles/OWSUserProfile.m b/SignalMessaging/profiles/OWSUserProfile.m index 460ca7d19..cb7727213 100644 --- a/SignalMessaging/profiles/OWSUserProfile.m +++ b/SignalMessaging/profiles/OWSUserProfile.m @@ -37,6 +37,12 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; @implementation OWSUserProfile ++ (NSString *)collection +{ + // Legacy class name. + return @"UserProfile"; +} + + (OWSUserProfile *)getOrBuildUserProfileForRecipientId:(NSString *)recipientId dbConnection:(YapDatabaseConnection *)dbConnection { @@ -329,13 +335,14 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; return TSYapDatabaseObject.dbReadWriteConnection; } +// This should only be used in verbose, developer-only logs. - (NSString *)debugDescription { - return [NSString stringWithFormat:@"%@ %p %@ %@ %@ %@ %@ %f", + return [NSString stringWithFormat:@"%@ %p %@ %zd %@ %@ %@ %f", self.logTag, self, self.recipientId, - self.profileKey.keyData.hexadecimalString, + self.profileKey.keyData.length, self.profileName, self.avatarUrlPath, self.avatarFileName,