diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 85ec492cb..1db27bc0f 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -108,7 +108,7 @@ 3478506B1FD9B78A007B8332 /* NoopCallMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */; }; 3478506C1FD9B78A007B8332 /* NoopNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */; }; 347850711FDAEB17007B8332 /* OWSUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 3478506F1FDAEB16007B8332 /* OWSUserProfile.m */; }; - 347850721FDAEB17007B8332 /* OWSUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850701FDAEB16007B8332 /* OWSUserProfile.h */; }; + 347850721FDAEB17007B8332 /* OWSUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850701FDAEB16007B8332 /* OWSUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; }; 3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; }; 34B0796D1FCF46B100E248C2 /* MainAppContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B0796B1FCF46B000E248C2 /* MainAppContext.m */; }; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 089addd83..28ae423b7 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -64,6 +64,7 @@ #import #import #import +#import #import #import #import diff --git a/Signal/src/ViewControllers/InboxTableViewCell.m b/Signal/src/ViewControllers/InboxTableViewCell.m index 50ced4ff0..de7c8fcfd 100644 --- a/Signal/src/ViewControllers/InboxTableViewCell.m +++ b/Signal/src/ViewControllers/InboxTableViewCell.m @@ -7,6 +7,7 @@ #import "Signal-Swift.h" #import "ViewControllerUtils.h" #import +#import #import #import #import diff --git a/Signal/src/ViewControllers/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsViewController.m index afacae8f2..0d850c793 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsViewController.m @@ -19,6 +19,7 @@ #import #import #import +#import #import #import #import diff --git a/SignalMessaging/SignalMessaging.h b/SignalMessaging/SignalMessaging.h index b049c7e2e..f8c0772e4 100644 --- a/SignalMessaging/SignalMessaging.h +++ b/SignalMessaging/SignalMessaging.h @@ -30,6 +30,7 @@ FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[]; #import #import #import +#import #import #import #import diff --git a/SignalMessaging/Views/ContactTableViewCell.m b/SignalMessaging/Views/ContactTableViewCell.m index 4c95fac78..d67b1d2c6 100644 --- a/SignalMessaging/Views/ContactTableViewCell.m +++ b/SignalMessaging/Views/ContactTableViewCell.m @@ -6,6 +6,7 @@ #import "Environment.h" #import "OWSContactAvatarBuilder.h" #import "OWSContactsManager.h" +#import "OWSUserProfile.h" #import "UIFont+OWS.h" #import "UIUtil.h" #import "UIView+OWS.h" diff --git a/SignalMessaging/contacts/OWSContactsManager.m b/SignalMessaging/contacts/OWSContactsManager.m index f67c8dbdf..1a7bf4fb0 100644 --- a/SignalMessaging/contacts/OWSContactsManager.m +++ b/SignalMessaging/contacts/OWSContactsManager.m @@ -6,6 +6,7 @@ #import "Environment.h" #import "OWSFormat.h" #import "OWSProfileManager.h" +#import "OWSUserProfile.h" #import "ViewControllerUtils.h" #import #import diff --git a/SignalMessaging/profiles/OWSProfileManager.h b/SignalMessaging/profiles/OWSProfileManager.h index 331dddb23..659ac9492 100644 --- a/SignalMessaging/profiles/OWSProfileManager.h +++ b/SignalMessaging/profiles/OWSProfileManager.h @@ -6,12 +6,7 @@ NS_ASSUME_NONNULL_BEGIN -extern NSString *const kNSNotificationName_LocalProfileDidChange; -extern NSString *const kNSNotificationName_OtherUsersProfileWillChange; -extern NSString *const kNSNotificationName_OtherUsersProfileDidChange; extern NSString *const kNSNotificationName_ProfileWhitelistDidChange; -extern NSString *const kNSNotificationKey_ProfileRecipientId; -extern NSString *const kNSNotificationKey_ProfileGroupId; extern const NSUInteger kOWSProfileManager_NameDataLength; extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index d59085e11..bd991ae53 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -33,12 +33,7 @@ NS_ASSUME_NONNULL_BEGIN -NSString *const kNSNotificationName_LocalProfileDidChange = @"kNSNotificationName_LocalProfileDidChange"; -NSString *const kNSNotificationName_OtherUsersProfileWillChange = @"kNSNotificationName_OtherUsersProfileWillChange"; -NSString *const kNSNotificationName_OtherUsersProfileDidChange = @"kNSNotificationName_OtherUsersProfileDidChange"; NSString *const kNSNotificationName_ProfileWhitelistDidChange = @"kNSNotificationName_ProfileWhitelistDidChange"; -NSString *const kNSNotificationKey_ProfileRecipientId = @"kNSNotificationKey_ProfileRecipientId"; -NSString *const kNSNotificationKey_ProfileGroupId = @"kNSNotificationKey_ProfileGroupId"; NSString *const kOWSProfileManager_UserWhitelistCollection = @"kOWSProfileManager_UserWhitelistCollection"; NSString *const kOWSProfileManager_GroupWhitelistCollection = @"kOWSProfileManager_GroupWhitelistCollection"; @@ -146,44 +141,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; #pragma mark - User Profile Accessor -- (OWSUserProfileCompletion)userProfileSaveCompletion:(OWSUserProfile *)userProfile -{ - OWSAssert(userProfile); - - return ^{ - BOOL isLocalUserProfile = userProfile == self.localUserProfile; - - dispatch_async(dispatch_get_main_queue(), ^{ - if (isLocalUserProfile) { - // We populate an initial (empty) profile on launch of a new install, but until - // we have a registered account, syncing will fail (and there could not be any - // linked device to sync to at this point anyway). - if ([TSAccountManager isRegistered]) { - [CurrentAppContext() doMultiDeviceUpdateWithProfileKey:userProfile.profileKey]; - } - - [[NSNotificationCenter defaultCenter] - postNotificationNameAsync:kNSNotificationName_LocalProfileDidChange - object:nil - userInfo:nil]; - } else { - [[NSNotificationCenter defaultCenter] - postNotificationNameAsync:kNSNotificationName_OtherUsersProfileWillChange - object:nil - userInfo:@{ - kNSNotificationKey_ProfileRecipientId : userProfile.recipientId, - }]; - [[NSNotificationCenter defaultCenter] - postNotificationNameAsync:kNSNotificationName_OtherUsersProfileDidChange - object:nil - userInfo:@{ - kNSNotificationKey_ProfileRecipientId : userProfile.recipientId, - }]; - } - }); - }; -} - - (void)ensureLocalProfileCached { // Since localUserProfile can create a transaction, we want to make sure it's not called for the first diff --git a/SignalMessaging/profiles/OWSUserProfile.h b/SignalMessaging/profiles/OWSUserProfile.h index 81281aaa6..cae7284c8 100644 --- a/SignalMessaging/profiles/OWSUserProfile.h +++ b/SignalMessaging/profiles/OWSUserProfile.h @@ -10,6 +10,13 @@ typedef void (^OWSUserProfileCompletion)(void); @class OWSAES256Key; +extern NSString *const kNSNotificationName_LocalProfileDidChange; +extern NSString *const kNSNotificationName_OtherUsersProfileWillChange; +extern NSString *const kNSNotificationName_OtherUsersProfileDidChange; + +extern NSString *const kNSNotificationKey_ProfileRecipientId; +extern NSString *const kNSNotificationKey_ProfileGroupId; + extern NSString *const kLocalProfileUniqueId; // This class should be completely thread-safe. diff --git a/SignalMessaging/profiles/OWSUserProfile.m b/SignalMessaging/profiles/OWSUserProfile.m index 675ce5ea5..834de26db 100644 --- a/SignalMessaging/profiles/OWSUserProfile.m +++ b/SignalMessaging/profiles/OWSUserProfile.m @@ -4,11 +4,21 @@ #import "OWSUserProfile.h" #import "NSString+OWS.h" +#import #import +#import +#import #import NS_ASSUME_NONNULL_BEGIN +NSString *const kNSNotificationName_LocalProfileDidChange = @"kNSNotificationName_LocalProfileDidChange"; +NSString *const kNSNotificationName_OtherUsersProfileWillChange = @"kNSNotificationName_OtherUsersProfileWillChange"; +NSString *const kNSNotificationName_OtherUsersProfileDidChange = @"kNSNotificationName_OtherUsersProfileDidChange"; + +NSString *const kNSNotificationKey_ProfileRecipientId = @"kNSNotificationKey_ProfileRecipientId"; +NSString *const kNSNotificationKey_ProfileGroupId = @"kNSNotificationKey_ProfileGroupId"; + NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; @interface OWSUserProfile () @@ -66,6 +76,46 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; #pragma mark - Update With... Methods +- (OWSUserProfileCompletion)updateWithCompletion:(nullable OWSUserProfileCompletion)externalCompletion +{ + return ^{ + if (externalCompletion) { + externalCompletion(); + } + + BOOL isLocalUserProfile = [self.recipientId isEqualToString:kLocalProfileUniqueId]; + + dispatch_async(dispatch_get_main_queue(), ^{ + if (isLocalUserProfile) { + // We populate an initial (empty) profile on launch of a new install, but until + // we have a registered account, syncing will fail (and there could not be any + // linked device to sync to at this point anyway). + if ([TSAccountManager isRegistered]) { + [CurrentAppContext() doMultiDeviceUpdateWithProfileKey:self.profileKey]; + } + + [[NSNotificationCenter defaultCenter] + postNotificationNameAsync:kNSNotificationName_LocalProfileDidChange + object:nil + userInfo:nil]; + } else { + [[NSNotificationCenter defaultCenter] + postNotificationNameAsync:kNSNotificationName_OtherUsersProfileWillChange + object:nil + userInfo:@{ + kNSNotificationKey_ProfileRecipientId : self.recipientId, + }]; + [[NSNotificationCenter defaultCenter] + postNotificationNameAsync:kNSNotificationName_OtherUsersProfileDidChange + object:nil + userInfo:@{ + kNSNotificationKey_ProfileRecipientId : self.recipientId, + }]; + } + }); + }; +} + - (void)updateWithProfileName:(nullable NSString *)profileName avatarUrlPath:(nullable NSString *)avatarUrlPath avatarFileName:(nullable NSString *)avatarFileName @@ -80,7 +130,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setAvatarFileName:avatarFileName]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateWithProfileName:(nullable NSString *)profileName @@ -99,7 +149,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setLastUpdateDate:lastUpdateDate]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateWithProfileName:(nullable NSString *)profileName @@ -116,7 +166,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setLastUpdateDate:lastUpdateDate]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateWithProfileName:(nullable NSString *)profileName @@ -135,7 +185,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setAvatarFileName:avatarFileName]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateWithAvatarUrlPath:(nullable NSString *)avatarUrlPath @@ -150,7 +200,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setAvatarFileName:avatarFileName]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateWithAvatarFileName:(nullable NSString *)avatarFileName @@ -163,7 +213,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setAvatarFileName:avatarFileName]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateWithLastUpdateDate:(nullable NSDate *)lastUpdateDate @@ -176,7 +226,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setLastUpdateDate:lastUpdateDate]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)clearWithProfileKey:(OWSAES256Key *)profileKey @@ -195,7 +245,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setLastUpdateDate:nil]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } - (void)updateImmediatelyWithProfileKey:(OWSAES256Key *)profileKey @@ -212,7 +262,7 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; [userProfile setProfileKey:profileKey]; }]; } - completionBlock:completion]; + completionBlock:[self updateWithCompletion:completion]]; } #pragma mark - Database Connection Accessors