diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index befff39e7..1f320c63b 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -525,7 +525,14 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); if (!localNumber) { return; } - [ProfileFetcherJob runWithRecipientId:localNumber ignoreThrottling:YES]; + [self fetchProfileForRecipientId:localNumber]; +} + +- (void)fetchProfileForRecipientId:(NSString *)recipientId +{ + OWSAssertIsOnMainThread(); + + [ProfileFetcherJob runWithRecipientId:recipientId ignoreThrottling:YES]; } #pragma mark - Profile Key Rotation @@ -997,8 +1004,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); dbConnection:self.dbConnection completion:^{ dispatch_async(dispatch_get_main_queue(), ^(void) { - [ProfileFetcherJob runWithRecipientId:recipientId - ignoreThrottling:YES]; + [self fetchProfileForRecipientId:recipientId]; }); }]; }); diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.m b/SignalServiceKit/src/Contacts/SignalRecipient.m index 89a2b1ef1..4ceda6a2e 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.m +++ b/SignalServiceKit/src/Contacts/SignalRecipient.m @@ -4,7 +4,10 @@ #import "SignalRecipient.h" #import "OWSDevice.h" +#import "ProfileManagerProtocol.h" +#import "SSKEnvironment.h" #import "TSAccountManager.h" +#import #import NS_ASSUME_NONNULL_BEGIN @@ -19,6 +22,20 @@ NS_ASSUME_NONNULL_BEGIN @implementation SignalRecipient +#pragma mark - Dependencies + +- (id)profileManager +{ + return SSKEnvironment.shared.profileManager; +} + +- (id)udManager +{ + return SSKEnvironment.shared.udManager; +} + +#pragma mark - + + (instancetype)getOrBuildUnsavedRecipientForRecipientId:(NSString *)recipientId transaction:(YapDatabaseReadTransaction *)transaction { @@ -127,6 +144,17 @@ NS_ASSUME_NONNULL_BEGIN if (devicesToRemove.count > 0) { [self removeDevicesFromRecipient:[NSSet setWithArray:devicesToRemove] transaction:transaction]; } + + // Device changes + dispatch_async(dispatch_get_main_queue(), ^{ + // Device changes can affect the UD access mode for a recipient, + // so we need to: + // + // * Mark the UD access mode as "unknown". + // * Fetch the profile for this user to update UD access mode. + [self.udManager setUnidentifiedAccessMode:UnidentifiedAccessModeUnknown recipientId:self.recipientId]; + [self.profileManager fetchProfileForRecipientId:self.recipientId]; + }); } - (void)addDevicesToRegisteredRecipient:(NSSet *)devices transaction:(YapDatabaseReadWriteTransaction *)transaction diff --git a/SignalServiceKit/src/Devices/OWSDevice.m b/SignalServiceKit/src/Devices/OWSDevice.m index 18a63aad1..b831ad55a 100644 --- a/SignalServiceKit/src/Devices/OWSDevice.m +++ b/SignalServiceKit/src/Devices/OWSDevice.m @@ -7,11 +7,13 @@ #import "OWSPrimaryStorage.h" #import "ProfileManagerProtocol.h" #import "SSKEnvironment.h" +#import "TSAccountManager.h" #import "YapDatabaseConnection+OWS.h" #import "YapDatabaseConnection.h" #import "YapDatabaseTransaction.h" #import #import +#import NS_ASSUME_NONNULL_BEGIN @@ -114,6 +116,25 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma @implementation OWSDevice +#pragma mark - Dependencies + ++ (id)profileManager +{ + return SSKEnvironment.shared.profileManager; +} + ++ (id)udManager +{ + return SSKEnvironment.shared.udManager; +} + ++ (TSAccountManager *)tsAccountManager +{ + return TSAccountManager.sharedInstance; +} + +#pragma mark - + - (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { [super saveWithTransaction:transaction]; @@ -177,7 +198,16 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma } if (didChange) { - [SSKEnvironment.shared.profileManager fetchLocalUsersProfile]; + dispatch_async(dispatch_get_main_queue(), ^{ + // Device changes can affect the UD access mode for a recipient, + // so we need to: + // + // * Mark the UD access mode as "unknown". + // * Fetch the profile for this user to update UD access mode. + [self.udManager setUnidentifiedAccessMode:UnidentifiedAccessModeUnknown + recipientId:self.tsAccountManager.localNumber]; + [self.profileManager fetchLocalUsersProfile]; + }); } } diff --git a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h index 2537676f7..be08179ac 100644 --- a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h +++ b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h @@ -23,6 +23,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)fetchLocalUsersProfile; +- (void)fetchProfileForRecipientId:(NSString *)recipientId; + @end NS_ASSUME_NONNULL_END