Merge branch 'mkirk/save-profile-to-contact'

pull/1/head
Michael Kirk 8 years ago
commit 6bb102783d

@ -57,6 +57,10 @@ extern NSString *const kNSNotificationName_OtherUsersProfileDidChange;
- (nullable UIImage *)profileAvatarForRecipientId:(NSString *)recipientId;
// Reads raw avatar data from disk if available. Uncached, so shouldn't be used frequently,
// but useful to get the raw image data for populating cnContact.imageData without lossily re-encoding.
- (nullable NSData *)profileAvatarDataForRecipientId:(NSString *)recipientId;
- (void)refreshProfileForRecipientId:(NSString *)recipientId;
- (void)updateProfileForRecipientId:(NSString *)recipientId

@ -718,6 +718,15 @@ static const NSUInteger kOWSProfileManager_NameDataLength = 26;
return userProfile.profileName;
}
- (nullable NSData *)profileAvatarDataForRecipientId:(NSString *)recipientId
{
UserProfile *userProfile = [self getOrBuildUserProfileForRecipientId:recipientId];
if (userProfile.avatarFileName.length > 0) {
return [self loadProfileDataWithFilename:userProfile.avatarFileName];
}
return nil;
}
- (nullable UIImage *)profileAvatarForRecipientId:(NSString *)recipientId
{
OWSAssert([NSThread isMainThread]);
@ -1001,12 +1010,20 @@ static const NSUInteger kOWSProfileManager_NameDataLength = 26;
#pragma mark - Avatar Disk Cache
- (nullable UIImage *)loadProfileAvatarWithFilename:(NSString *)fileName
- (nullable NSData *)loadProfileDataWithFilename:(NSString *)filename
{
OWSAssert(fileName.length > 0);
OWSAssert(filename.length > 0);
NSString *filePath = [self.profileAvatarsDirPath stringByAppendingPathComponent:fileName];
UIImage *_Nullable image = [UIImage imageWithContentsOfFile:filePath];
NSString *filePath = [self.profileAvatarsDirPath stringByAppendingPathComponent:filename];
return [NSData dataWithContentsOfFile:filePath];
}
- (nullable UIImage *)loadProfileAvatarWithFilename:(NSString *)filename
{
OWSAssert(filename.length > 0);
NSString *filePath = [self.profileAvatarsDirPath stringByAppendingPathComponent:filename];
UIImage *_Nullable image = [UIImage imageWithData:[self loadProfileDataWithFilename:filename]];
return image;
}

@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* NOTE: This method calls `[UIUtil applyDefaultSystemAppearence]`.
* When using this method, you must call `[UIUtil applySignalAppearence]` once contact editing is finished;
* When using this method, you must call `[UIUtil applySignalAppearence]` once contact editing is finished;
*/
- (void)presentContactViewControllerForRecipientId:(NSString *)recipientId
fromViewController:(UIViewController<ContactEditingDelegate> *)fromViewController

@ -5,6 +5,7 @@
#import "ContactsViewHelper.h"
#import "ContactTableViewCell.h"
#import "Environment.h"
#import "OWSProfileManager.h"
#import "Signal-Swift.h"
#import <SignalServiceKit/Contact.h>
#import <SignalServiceKit/OWSBlockingManager.h>
@ -28,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) BOOL shouldNotifyDelegateOfUpdatedContacts;
@property (nonatomic) BOOL hasUpdatedContactsAtLeastOnce;
@property (nonatomic) OWSProfileManager *profileManager;
@end
@ -49,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
_blockedPhoneNumbers = [_blockingManager blockedPhoneNumbers];
_contactsManager = [Environment getCurrent].contactsManager;
_profileManager = [OWSProfileManager sharedManager];
// We don't want to notify the delegate in the `updateContacts`.
self.shouldNotifyDelegateOfUpdatedContacts = YES;
@ -410,6 +413,9 @@ NS_ASSUME_NONNULL_BEGIN
[CNLabeledValue labeledValueWithLabel:CNLabelPhoneNumberMain value:phoneNumber];
newContact.phoneNumbers = @[ labeledPhoneNumber ];
newContact.givenName = [self.profileManager profileNameForRecipientId:recipientId];
newContact.imageData = [self.profileManager profileAvatarDataForRecipientId:recipientId];
contactViewController = [CNContactViewController viewControllerForNewContact:newContact];
}

Loading…
Cancel
Save