diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 4213a5b75..3c86df26c 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -77,6 +77,8 @@ 34CCAF381F0C0599004084F4 /* AppUpdateNag.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF371F0C0599004084F4 /* AppUpdateNag.m */; }; 34CCAF3B1F0C2748004084F4 /* OWSAddToContactViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF3A1F0C2748004084F4 /* OWSAddToContactViewController.m */; }; 34CE88E71F2FB9A10098030F /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88E61F2FB9A10098030F /* ProfileViewController.m */; }; + 34CE88EC1F3237260098030F /* OWSProfileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88EA1F3237260098030F /* OWSProfileManager.m */; }; + 34CE88ED1F3237260098030F /* ProfileFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88EB1F3237260098030F /* ProfileFetcherJob.swift */; }; 34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */; }; 34D5CCA91EAE3D30005515DB /* AvatarViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCA81EAE3D30005515DB /* AvatarViewHelper.m */; }; 34D5CCB11EAE7E7F005515DB /* SelectRecipientViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D5CCB01EAE7E7F005515DB /* SelectRecipientViewController.m */; }; @@ -168,7 +170,6 @@ 45855F371D9498A40084F340 /* OWSContactAvatarBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */; }; 45855F381D9498A40084F340 /* OWSContactAvatarBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */; }; 4585C4601ED4FD0400896AEA /* OWS104CreateRecipientIdentities.m in Sources */ = {isa = PBXBuildFile; fileRef = 4585C45F1ED4FD0400896AEA /* OWS104CreateRecipientIdentities.m */; }; - 4585C4661ED5DF7A00896AEA /* ProfileFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4585C4651ED5DF7A00896AEA /* ProfileFetcherJob.swift */; }; 4585C4681ED8F8D200896AEA /* SafetyNumberConfirmationAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4585C4671ED8F8D200896AEA /* SafetyNumberConfirmationAlert.swift */; }; 458967111DC117CC00E9DD21 /* AccountManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 458967101DC117CC00E9DD21 /* AccountManagerTest.swift */; }; 458DE9D61DEE3FD00071BB03 /* PeerConnectionClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 458DE9D51DEE3FD00071BB03 /* PeerConnectionClient.swift */; }; @@ -506,6 +507,9 @@ 34CCAF3A1F0C2748004084F4 /* OWSAddToContactViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSAddToContactViewController.m; sourceTree = ""; }; 34CE88E51F2FB9A10098030F /* ProfileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProfileViewController.h; sourceTree = ""; }; 34CE88E61F2FB9A10098030F /* ProfileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProfileViewController.m; sourceTree = ""; }; + 34CE88E91F3237260098030F /* OWSProfileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSProfileManager.h; sourceTree = ""; }; + 34CE88EA1F3237260098030F /* OWSProfileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSProfileManager.m; sourceTree = ""; }; + 34CE88EB1F3237260098030F /* ProfileFetcherJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileFetcherJob.swift; sourceTree = ""; }; 34D5CC941EA6AFAD005515DB /* OWSContactsSyncing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSContactsSyncing.h; sourceTree = ""; }; 34D5CC951EA6AFAD005515DB /* OWSContactsSyncing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSyncing.m; sourceTree = ""; }; 34D5CC981EA6EB79005515DB /* OWSMessageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageCollectionViewCell.h; sourceTree = ""; }; @@ -1074,6 +1078,16 @@ path = TSMessageAdapters; sourceTree = ""; }; + 34CE88E81F3237260098030F /* Profiles */ = { + isa = PBXGroup; + children = ( + 34CE88E91F3237260098030F /* OWSProfileManager.h */, + 34CE88EA1F3237260098030F /* OWSProfileManager.m */, + 34CE88EB1F3237260098030F /* ProfileFetcherJob.swift */, + ); + path = Profiles; + sourceTree = ""; + }; 34D8C0221ED3673300188D7C /* DebugUI */ = { isa = PBXGroup; children = ( @@ -1274,21 +1288,22 @@ 76EB03C118170B33006006FC /* src */ = { isa = PBXGroup; children = ( - 45CD81A41DBFF8CF004C9430 /* Storyboards */, 76EB03C218170B33006006FC /* AppDelegate.h */, 76EB03C318170B33006006FC /* AppDelegate.m */, 76EB03FE18170B33006006FC /* call */, 76EB040318170B33006006FC /* contact */, 70DBA29918CFE98500771DAD /* crypto */, 76EB041118170B33006006FC /* environment */, - 76EB041D18170B33006006FC /* network */, - B60959791C2C0FA9004E8797 /* rating */, - 76EB04C818170B33006006FC /* util */, 45D231751DC7E8C50034FA89 /* Jobs */, 457F3AC01D14A0F700C51351 /* Models */, - 450DF2061E0DD28D003D14BE /* UserInterface */, + 76EB041D18170B33006006FC /* network */, 45BFFFA51D898AB8004A12A7 /* Observers */, + 34CE88E81F3237260098030F /* Profiles */, + B60959791C2C0FA9004E8797 /* rating */, 45B201741DAECBFD00C461E0 /* Signal-Bridging-Header.h */, + 45CD81A41DBFF8CF004C9430 /* Storyboards */, + 450DF2061E0DD28D003D14BE /* UserInterface */, + 76EB04C818170B33006006FC /* util */, ); path = src; sourceTree = ""; @@ -2123,7 +2138,6 @@ buildActionMask = 2147483647; files = ( 34B3F8761E8DF1700035BE1A /* CodeVerificationViewController.m in Sources */, - 4585C4661ED5DF7A00896AEA /* ProfileFetcherJob.swift in Sources */, 76EB063E18170B33006006FC /* Operation.m in Sources */, 34B3F8741E8DF1700035BE1A /* AttachmentSharing.m in Sources */, 34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */, @@ -2139,10 +2153,12 @@ 3456710A1E8A9F5D006EE662 /* TSGenericAttachmentAdapter.m in Sources */, 450DF2091E0DD2C6003D14BE /* UserNotificationsAdaptee.swift in Sources */, 340CB2241EAC155C0001CAA1 /* ContactsViewHelper.m in Sources */, + 34CE88EC1F3237260098030F /* OWSProfileManager.m in Sources */, 45CD81F21DC03A22004C9430 /* OWSLogger.m in Sources */, 4542F0941EB9372700C7EE92 /* SystemContactsFetcher.swift in Sources */, B60C16651988999D00E97A6C /* VersionMigrations.m in Sources */, B97940271832BD2400BD66CB /* UIUtil.m in Sources */, + 34CE88ED1F3237260098030F /* ProfileFetcherJob.swift in Sources */, 34B3F8791E8DF1700035BE1A /* CountryCodeViewController.m in Sources */, 4CE0E3771B954546007210CF /* TSAnimatedAdapter.m in Sources */, 4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */, diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 367869aad..ff0321d70 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -11,6 +11,7 @@ #import "NotificationsManager.h" #import "OWSContactsManager.h" #import "OWSContactsSyncing.h" +#import "OWSProfileManager.h" #import "OWSStaleNotificationObserver.h" #import "Pastelog.h" #import "PropertyListPreferences.h" @@ -28,7 +29,6 @@ #import #import #import -#import #import #import #import @@ -161,7 +161,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; DDLogInfo(@"%@ application: didFinishLaunchingWithOptions completed.", self.tag); [OWSAnalytics appLaunchDidBegin]; - [OWSProfilesManager.sharedManager appLaunchDidBegin]; return YES; } @@ -236,7 +235,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [[TextSecureKitEnv alloc] initWithCallMessageHandler:[Environment getCurrent].callMessageHandler contactsManager:[Environment getCurrent].contactsManager messageSender:[Environment getCurrent].messageSender - notificationsManager:[Environment getCurrent].notificationsManager]; + notificationsManager:[Environment getCurrent].notificationsManager + profileManager:OWSProfileManager.sharedManager]; [TextSecureKitEnv setSharedEnv:sharedEnv]; [[TSStorageManager sharedManager] setupDatabaseWithSafeBlockingMigrations:^{ diff --git a/SignalServiceKit/src/Profiles/OWSProfilesManager.h b/Signal/src/Profiles/OWSProfileManager.h similarity index 90% rename from SignalServiceKit/src/Profiles/OWSProfilesManager.h rename to Signal/src/Profiles/OWSProfileManager.h index c61ec32ec..5503f80a6 100644 --- a/SignalServiceKit/src/Profiles/OWSProfilesManager.h +++ b/Signal/src/Profiles/OWSProfileManager.h @@ -2,6 +2,8 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // +#import + NS_ASSUME_NONNULL_BEGIN extern NSString *const kNSNotificationName_LocalProfileDidChange; @@ -10,7 +12,7 @@ extern NSString *const kNSNotificationName_OtherUsersProfileDidChange; @class TSThread; // This class can be safely accessed and used from any thread. -@interface OWSProfilesManager : NSObject +@interface OWSProfileManager : NSObject - (instancetype)init NS_UNAVAILABLE; @@ -33,9 +35,6 @@ extern NSString *const kNSNotificationName_OtherUsersProfileDidChange; success:(void (^)())successBlock failure:(void (^)())failureBlock; -// This method should only be called from the main thread. -- (void)appLaunchDidBegin; - #pragma mark - Profile Whitelist - (void)addUserToProfileWhitelist:(NSString *)recipientId; @@ -50,7 +49,7 @@ extern NSString *const kNSNotificationName_OtherUsersProfileDidChange; #pragma mark - Other User's Profiles -+ (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId; +- (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId; - (nullable NSData *)profileKeyForRecipientId:(NSString *)recipientId; diff --git a/SignalServiceKit/src/Profiles/OWSProfilesManager.m b/Signal/src/Profiles/OWSProfileManager.m similarity index 91% rename from SignalServiceKit/src/Profiles/OWSProfilesManager.m rename to Signal/src/Profiles/OWSProfileManager.m index 3b14981ac..2ff9c417f 100644 --- a/SignalServiceKit/src/Profiles/OWSProfilesManager.m +++ b/Signal/src/Profiles/OWSProfileManager.m @@ -2,16 +2,18 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "OWSProfilesManager.h" -#import "NSData+hexString.h" -#import "NSDate+OWS.h" -#import "OWSMessageSender.h" -#import "SecurityUtils.h" -#import "TSGroupThread.h" -#import "TSStorageManager.h" -#import "TSThread.h" -#import "TSYapDatabaseObject.h" -#import "TextSecureKitEnv.h" +#import "OWSProfileManager.h" +#import "Environment.h" +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import NS_ASSUME_NONNULL_BEGIN @@ -27,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable) NSString *avatarUrl; @property (nonatomic, nullable) NSString *avatarDigest; -// This filename is relative to OWSProfilesManager.profileAvatarsDirPath. +// This filename is relative to OWSProfileManager.profileAvatarsDirPath. @property (nonatomic, nullable) NSString *avatarFileName; // This should reflect when either: @@ -85,13 +87,13 @@ NSString *const kNSNotificationName_LocalProfileUniqueId = @"kNSNotificationName NSString *const kNSNotificationName_LocalProfileDidChange = @"kNSNotificationName_LocalProfileDidChange"; NSString *const kNSNotificationName_OtherUsersProfileDidChange = @"kNSNotificationName_OtherUsersProfileDidChange"; -NSString *const kOWSProfilesManager_UserWhitelistCollection = @"kOWSProfilesManager_UserWhitelistCollection"; -NSString *const kOWSProfilesManager_GroupWhitelistCollection = @"kOWSProfilesManager_GroupWhitelistCollection"; +NSString *const kOWSProfileManager_UserWhitelistCollection = @"kOWSProfileManager_UserWhitelistCollection"; +NSString *const kOWSProfileManager_GroupWhitelistCollection = @"kOWSProfileManager_GroupWhitelistCollection"; // TODO: static const NSInteger kProfileKeyLength = 16; -@interface OWSProfilesManager () +@interface OWSProfileManager () @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @@ -113,11 +115,11 @@ static const NSInteger kProfileKeyLength = 16; #pragma mark - -@implementation OWSProfilesManager +@implementation OWSProfileManager + (instancetype)sharedManager { - static OWSProfilesManager *sharedMyManager = nil; + static OWSProfileManager *sharedMyManager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedMyManager = [[self alloc] initDefault]; @@ -128,7 +130,7 @@ static const NSInteger kProfileKeyLength = 16; - (instancetype)initDefault { TSStorageManager *storageManager = [TSStorageManager sharedManager]; - OWSMessageSender *messageSender = [TextSecureKitEnv sharedEnv].messageSender; + OWSMessageSender *messageSender = [Environment getCurrent].messageSender; return [self initWithStorageManager:storageManager messageSender:messageSender]; } @@ -157,7 +159,7 @@ static const NSInteger kProfileKeyLength = 16; self.localUserProfile = [self getOrCreateUserProfileForRecipientId:kNSNotificationName_LocalProfileUniqueId]; OWSAssert(self.localUserProfile); if (!self.localUserProfile.profileKey) { - self.localUserProfile.profileKey = [OWSProfilesManager generateLocalProfileKey]; + self.localUserProfile.profileKey = [OWSProfileManager generateLocalProfileKey]; // Make sure to save on the local db connection for consistency. // // NOTE: we do an async read/write here to avoid blocking during app launch path. @@ -183,11 +185,6 @@ static const NSInteger kProfileKeyLength = 16; object:nil]; } -- (void)appLaunchDidBegin -{ - // Do nothing; we only want to make sure this singleton is created on startup. -} - #pragma mark - User Profile Accessor // This method can be safely called from any thread. @@ -422,7 +419,7 @@ static const NSInteger kProfileKeyLength = 16; OWSAssert([NSThread isMainThread]); OWSAssert(recipientId.length > 0); - [self.dbConnection setBool:YES forKey:recipientId inCollection:kOWSProfilesManager_UserWhitelistCollection]; + [self.dbConnection setBool:YES forKey:recipientId inCollection:kOWSProfileManager_UserWhitelistCollection]; self.userProfileWhitelistCache[recipientId] = @(YES); } @@ -444,7 +441,7 @@ static const NSInteger kProfileKeyLength = 16; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { for (NSString *recipientId in recipientIds) { - [transaction setObject:@(YES) forKey:recipientId inCollection:kOWSProfilesManager_UserWhitelistCollection]; + [transaction setObject:@(YES) forKey:recipientId inCollection:kOWSProfileManager_UserWhitelistCollection]; self.userProfileWhitelistCache[recipientId] = @(YES); } }]; @@ -459,7 +456,7 @@ static const NSInteger kProfileKeyLength = 16; return [value boolValue]; } - value = @([self.dbConnection hasObjectForKey:recipientId inCollection:kOWSProfilesManager_UserWhitelistCollection]); + value = @([self.dbConnection hasObjectForKey:recipientId inCollection:kOWSProfileManager_UserWhitelistCollection]); self.userProfileWhitelistCache[recipientId] = value; return [value boolValue]; } @@ -469,7 +466,7 @@ static const NSInteger kProfileKeyLength = 16; OWSAssert(groupId.length > 0); NSString *groupIdKey = [groupId hexadecimalString]; - [self.dbConnection setObject:@(1) forKey:groupIdKey inCollection:kOWSProfilesManager_GroupWhitelistCollection]; + [self.dbConnection setObject:@(1) forKey:groupIdKey inCollection:kOWSProfileManager_GroupWhitelistCollection]; self.groupProfileWhitelistCache[groupIdKey] = @(YES); } @@ -484,7 +481,7 @@ static const NSInteger kProfileKeyLength = 16; } value = - @(nil != [self.dbConnection objectForKey:groupIdKey inCollection:kOWSProfilesManager_GroupWhitelistCollection]); + @(nil != [self.dbConnection objectForKey:groupIdKey inCollection:kOWSProfileManager_GroupWhitelistCollection]); self.groupProfileWhitelistCache[groupIdKey] = value; return [value boolValue]; } @@ -496,10 +493,10 @@ static const NSInteger kProfileKeyLength = 16; if (thread.isGroupThread) { TSGroupThread *groupThread = (TSGroupThread *)thread; NSData *groupId = groupThread.groupModel.groupId; - return [OWSProfilesManager.sharedManager isGroupIdInProfileWhitelist:groupId]; + return [self isGroupIdInProfileWhitelist:groupId]; } else { NSString *recipientId = thread.contactIdentifier; - return [OWSProfilesManager.sharedManager isUserInProfileWhitelist:recipientId]; + return [self isUserInProfileWhitelist:recipientId]; } } @@ -507,7 +504,7 @@ static const NSInteger kProfileKeyLength = 16; { OWSAssert([NSThread isMainThread]); OWSAssert(contactRecipientIds); - + // TODO: The persisted whitelist could either be: // // * Just users manually added to the whitelist. @@ -518,32 +515,26 @@ static const NSInteger kProfileKeyLength = 16; #pragma mark - Other User's Profiles -+ (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId -{ - dispatch_async(dispatch_get_main_queue(), ^{ - [[self sharedManager] setProfileKey:profileKey forRecipientId:recipientId]; - }); -} - - (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId { - OWSAssert([NSThread isMainThread]); OWSAssert(profileKey.length == kProfileKeyLength); OWSAssert(recipientId.length > 0); if (profileKey.length != kProfileKeyLength) { return; } - UserProfile *userProfile = [self getOrCreateUserProfileForRecipientId:recipientId]; - OWSAssert(userProfile); - if (userProfile.profileKey && [userProfile.profileKey isEqual:profileKey]) { - // Ignore redundant update. - return; - } + dispatch_async(dispatch_get_main_queue(), ^{ + UserProfile *userProfile = [self getOrCreateUserProfileForRecipientId:recipientId]; + OWSAssert(userProfile); + if (userProfile.profileKey && [userProfile.profileKey isEqual:profileKey]) { + // Ignore redundant update. + return; + } - userProfile.profileKey = profileKey; + userProfile.profileKey = profileKey; - [self saveUserProfile:userProfile]; + [self saveUserProfile:userProfile]; + }); } - (nullable NSData *)profileKeyForRecipientId:(NSString *)recipientId diff --git a/Signal/src/ProfileFetcherJob.swift b/Signal/src/Profiles/ProfileFetcherJob.swift similarity index 100% rename from Signal/src/ProfileFetcherJob.swift rename to Signal/src/Profiles/ProfileFetcherJob.swift diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index b21059e4b..657049768 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -75,7 +75,6 @@ #import #import #import -#import #import #import #import @@ -967,7 +966,6 @@ typedef enum : NSUInteger { } [self updateNavigationBarSubtitleLabel]; [ProfileFetcherJob runWithThread:self.thread networkManager:self.networkManager]; - [OWSProfilesManager.sharedManager refreshProfilesForThread:self.thread]; [self markVisibleMessagesAsRead]; } diff --git a/Signal/src/ViewControllers/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsViewController.m index d13979576..371aae256 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsViewController.m @@ -11,6 +11,7 @@ #import "OWSAvatarBuilder.h" #import "OWSBlockingManager.h" #import "OWSContactsManager.h" +#import "OWSProfileManager.h" #import "PhoneNumber.h" #import "ShowGroupMembersViewController.h" #import "Signal-Swift.h" @@ -24,7 +25,6 @@ #import #import #import -#import #import #import #import @@ -294,7 +294,7 @@ NS_ASSUME_NONNULL_BEGIN }]]; } - if ([OWSProfilesManager.sharedManager isThreadInProfileWhitelist:self.thread]) { + if ([OWSProfileManager.sharedManager isThreadInProfileWhitelist:self.thread]) { [mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ return [weakSelf labelCellWithName:(self.isGroupThread @@ -804,10 +804,10 @@ NS_ASSUME_NONNULL_BEGIN if (self.isGroupThread) { TSGroupThread *groupThread = (TSGroupThread *)self.thread; NSData *groupId = groupThread.groupModel.groupId; - [OWSProfilesManager.sharedManager addGroupIdToProfileWhitelist:groupId]; + [OWSProfileManager.sharedManager addGroupIdToProfileWhitelist:groupId]; } else { NSString *recipientId = self.thread.contactIdentifier; - [OWSProfilesManager.sharedManager addUserToProfileWhitelist:recipientId]; + [OWSProfileManager.sharedManager addUserToProfileWhitelist:recipientId]; } [self updateTableContents]; diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 915fa5656..14a62076f 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -4,12 +4,12 @@ #import "ProfileViewController.h" #import "AvatarViewHelper.h" +#import "OWSProfileManager.h" #import "Signal-Swift.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" #import "UIView+OWS.h" #import "UIViewController+OWS.h" -#import NS_ASSUME_NONNULL_BEGIN @@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN _avatarViewHelper = [AvatarViewHelper new]; _avatarViewHelper.delegate = self; - _avatar = [OWSProfilesManager.sharedManager localProfileAvatarImage]; + _avatar = [OWSProfileManager.sharedManager localProfileAvatarImage]; [self createViews]; } @@ -59,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN _nameTextField.placeholder = NSLocalizedString( @"PROFILE_VIEW_NAME_DEFAULT_TEXT", @"Default text for the profile name field of the profile view."); _nameTextField.delegate = self; - _nameTextField.text = [OWSProfilesManager.sharedManager localProfileName]; + _nameTextField.text = [OWSProfileManager.sharedManager localProfileName]; [_nameTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; _avatarView = [AvatarImageView new]; @@ -212,14 +212,14 @@ NS_ASSUME_NONNULL_BEGIN - (void)updateProfile { __weak ProfileViewController *weakSelf = self; - [OWSProfilesManager.sharedManager updateLocalProfileName:self.nameTextField.text - avatarImage:self.avatar - success:^{ - [weakSelf.navigationController popViewControllerAnimated:YES]; - } - failure:^{ - // TODO: Handle failure. - }]; + [OWSProfileManager.sharedManager updateLocalProfileName:self.nameTextField.text + avatarImage:self.avatar + success:^{ + [weakSelf.navigationController popViewControllerAnimated:YES]; + } + failure:^{ + // TODO: Handle failure. + }]; } #pragma mark - UITextFieldDelegate diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 287443b2c..ae7b641a1 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -4,12 +4,12 @@ #import "OWSContactsManager.h" #import "Environment.h" +#import "OWSProfileManager.h" #import "Signal-Swift.h" #import "Util.h" #import "ViewControllerUtils.h" #import #import -#import #import #import @@ -206,7 +206,7 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account self.signalAccountMap = [signalAccountMap copy]; self.signalAccounts = [signalAccounts copy]; - [OWSProfilesManager.sharedManager setContactRecipientIds:signalAccountMap.allKeys]; + [OWSProfileManager.sharedManager setContactRecipientIds:signalAccountMap.allKeys]; [self updateCachedDisplayNames]; }); diff --git a/Signal/test/util/ExceptionsTest.m b/Signal/test/util/ExceptionsTest.m index cac5a7efb..ce6fc6ee3 100644 --- a/Signal/test/util/ExceptionsTest.m +++ b/Signal/test/util/ExceptionsTest.m @@ -6,6 +6,7 @@ #import "TestUtil.h" @implementation ExceptionsTest + - (void)testContracts { ows_require(1 + 1 == 2); @try { diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 30a53ffd4..80b8682b1 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -5,12 +5,13 @@ #import "TSOutgoingMessage.h" #import "NSDate+millisecondTimeStamp.h" #import "OWSOutgoingSyncMessage.h" -#import "OWSProfilesManager.h" #import "OWSSignalServiceProtos.pb.h" +#import "ProfileManagerProtocol.h" #import "SignalRecipient.h" #import "TSAttachmentStream.h" #import "TSContactThread.h" #import "TSGroupThread.h" +#import "TextSecureKitEnv.h" #import #import @@ -464,7 +465,10 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec OWSAssert(contentBuilder); OWSAssert(recipient); - OWSAssert(OWSProfilesManager.sharedManager.localProfileKey.length > 0); + id profileManager = [TextSecureKitEnv sharedEnv].profileManager; + NSData *localProfileKey = profileManager.localProfileKey; + + OWSAssert(localProfileKey.length > 0); BOOL shouldIncludeProfileKey = NO; if ([self isKindOfClass:[OWSOutgoingSyncMessage class]]) { @@ -478,15 +482,15 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec // // For Group threads, we want to include the profile key IFF the // recipient OR the group is in the whitelist. - if ([OWSProfilesManager.sharedManager isUserInProfileWhitelist:recipient.recipientId]) { + if ([profileManager isUserInProfileWhitelist:recipient.recipientId]) { shouldIncludeProfileKey = YES; - } else if ([OWSProfilesManager.sharedManager isThreadInProfileWhitelist:self.thread]) { + } else if ([profileManager isThreadInProfileWhitelist:self.thread]) { shouldIncludeProfileKey = YES; } } if (shouldIncludeProfileKey) { - [contentBuilder setProfileKey:OWSProfilesManager.sharedManager.localProfileKey]; + [contentBuilder setProfileKey:localProfileKey]; } } diff --git a/SignalServiceKit/src/Messages/TSMessagesManager.m b/SignalServiceKit/src/Messages/TSMessagesManager.m index aae36da91..79164dda7 100644 --- a/SignalServiceKit/src/Messages/TSMessagesManager.m +++ b/SignalServiceKit/src/Messages/TSMessagesManager.m @@ -19,12 +19,12 @@ #import "OWSIncomingMessageFinder.h" #import "OWSIncomingSentMessageTranscript.h" #import "OWSMessageSender.h" -#import "OWSProfilesManager.h" #import "OWSReadReceiptsProcessor.h" #import "OWSRecordTranscriptJob.h" #import "OWSSyncContactsMessage.h" #import "OWSSyncGroupsMessage.h" #import "OWSSyncGroupsRequestMessage.h" +#import "ProfileManagerProtocol.h" #import "TSAccountManager.h" #import "TSAttachmentStream.h" #import "TSCall.h" @@ -499,7 +499,8 @@ NS_ASSUME_NONNULL_BEGIN if ([content hasProfileKey]) { NSData *profileKey = [content profileKey]; NSString *recipientId = envelope.source; - [OWSProfilesManager setProfileKey:profileKey forRecipientId:recipientId]; + id profileManager = [TextSecureKitEnv sharedEnv].profileManager; + [profileManager setProfileKey:profileKey forRecipientId:recipientId]; } if (content.hasSyncMessage) { diff --git a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h new file mode 100644 index 000000000..ac1b750ee --- /dev/null +++ b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h @@ -0,0 +1,17 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +@class TSThread; + +@protocol ProfileManagerProtocol + +- (NSData *)localProfileKey; + +- (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId; + +- (BOOL)isUserInProfileWhitelist:(NSString *)recipientId; + +- (BOOL)isThreadInProfileWhitelist:(TSThread *)thread; + +@end diff --git a/SignalServiceKit/src/TextSecureKitEnv.h b/SignalServiceKit/src/TextSecureKitEnv.h index 424f6daed..11642e215 100644 --- a/SignalServiceKit/src/TextSecureKitEnv.h +++ b/SignalServiceKit/src/TextSecureKitEnv.h @@ -8,13 +8,15 @@ NS_ASSUME_NONNULL_BEGIN @class OWSMessageSender; @protocol NotificationsProtocol; @protocol OWSCallMessageHandler; +@protocol ProfileManagerProtocol; @interface TextSecureKitEnv : NSObject - (instancetype)initWithCallMessageHandler:(id)callMessageHandler contactsManager:(id)contactsManager messageSender:(OWSMessageSender *)messageSender - notificationsManager:(id)notificationsManager NS_DESIGNATED_INITIALIZER; + notificationsManager:(id)notificationsManager + profileManager:(id)profileManager NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; @@ -25,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) id contactsManager; @property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) id notificationsManager; +@property (nonatomic, readonly) id profileManager; @end diff --git a/SignalServiceKit/src/TextSecureKitEnv.m b/SignalServiceKit/src/TextSecureKitEnv.m index aba5ed412..8bda6af70 100644 --- a/SignalServiceKit/src/TextSecureKitEnv.m +++ b/SignalServiceKit/src/TextSecureKitEnv.m @@ -11,12 +11,14 @@ static TextSecureKitEnv *TextSecureKitEnvSharedInstance; @implementation TextSecureKitEnv @synthesize callMessageHandler = _callMessageHandler, contactsManager = _contactsManager, - messageSender = _messageSender, notificationsManager = _notificationsManager; + messageSender = _messageSender, notificationsManager = _notificationsManager, + profileManager = _profileManager; - (instancetype)initWithCallMessageHandler:(id)callMessageHandler contactsManager:(id)contactsManager messageSender:(OWSMessageSender *)messageSender notificationsManager:(id)notificationsManager + profileManager:(id)profileManager { self = [super init]; if (!self) { @@ -27,6 +29,7 @@ static TextSecureKitEnv *TextSecureKitEnvSharedInstance; _contactsManager = contactsManager; _messageSender = messageSender; _notificationsManager = notificationsManager; + _profileManager = profileManager; return self; } @@ -71,6 +74,12 @@ static TextSecureKitEnv *TextSecureKitEnvSharedInstance; return _notificationsManager; } +- (id)profileManager +{ + NSAssert(_profileManager, @"Trying to access the profileManager before it's set."); + return _profileManager; +} + @end NS_ASSUME_NONNULL_END