Respond to CR; handle device changes in SignalRecipient as well.

pull/1/head
Matthew Chen 7 years ago
parent 55369a1ca3
commit 9c161e913d

@ -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];
});
}];
});

@ -4,7 +4,10 @@
#import "SignalRecipient.h"
#import "OWSDevice.h"
#import "ProfileManagerProtocol.h"
#import "SSKEnvironment.h"
#import "TSAccountManager.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
#import <YapDatabase/YapDatabaseConnection.h>
NS_ASSUME_NONNULL_BEGIN
@ -19,6 +22,20 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SignalRecipient
#pragma mark - Dependencies
- (id<ProfileManagerProtocol>)profileManager
{
return SSKEnvironment.shared.profileManager;
}
- (id<OWSUDManager>)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

@ -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 <Mantle/MTLValueTransformer.h>
#import <SignalCoreKit/NSDate+OWS.h>
#import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
@ -114,6 +116,25 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma
@implementation OWSDevice
#pragma mark - Dependencies
+ (id<ProfileManagerProtocol>)profileManager
{
return SSKEnvironment.shared.profileManager;
}
+ (id<OWSUDManager>)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];
});
}
}

@ -23,6 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)fetchLocalUsersProfile;
- (void)fetchProfileForRecipientId:(NSString *)recipientId;
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save