parent
efcd42012c
commit
518f15155a
|
@ -147,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (void)provisionWithParser:(OWSDeviceProvisioningURLParser *)parser
|
||||
{
|
||||
// Optimistically set this flag.
|
||||
[OWSDevice setMayHaveLinkedDevices:YES dbConnection:self.dbConnection];
|
||||
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES dbConnection:self.dbConnection];
|
||||
|
||||
ECKeyPair *_Nullable identityKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair];
|
||||
OWSAssert(identityKeyPair);
|
||||
|
|
|
@ -9,6 +9,19 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
extern uint32_t const OWSDevicePrimaryDeviceId;
|
||||
|
||||
@interface OWSDeviceManager : NSObject
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
+ (instancetype)sharedManager;
|
||||
|
||||
- (BOOL)mayHaveLinkedDevices:(YapDatabaseConnection *)dbConnection;
|
||||
- (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSDevice : TSYapDatabaseObject <MTLJSONSerializing>
|
||||
|
||||
@property (nonatomic, readonly) NSInteger deviceId;
|
||||
|
@ -52,11 +65,6 @@ extern uint32_t const OWSDevicePrimaryDeviceId;
|
|||
*/
|
||||
- (BOOL)updateAttributesWithDevice:(OWSDevice *)other;
|
||||
|
||||
#pragma mark - "May Have Linked Devices" Flag
|
||||
|
||||
+ (BOOL)mayHaveLinkedDevices:(YapDatabaseConnection *)dbConnection;
|
||||
+ (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -16,6 +16,67 @@ uint32_t const OWSDevicePrimaryDeviceId = 1;
|
|||
NSString *const kTSStorageManager_OWSDeviceCollection = @"kTSStorageManager_OWSDeviceCollection";
|
||||
NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_MayHaveLinkedDevices";
|
||||
|
||||
@interface OWSDeviceManager ()
|
||||
|
||||
@property (atomic, nullable) NSNumber *mayHaveLinkedDevicesCached;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSDeviceManager
|
||||
|
||||
+ (instancetype)sharedManager
|
||||
{
|
||||
static OWSDeviceManager *instance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[self alloc] initDefault];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)initDefault
|
||||
{
|
||||
return [super init];
|
||||
}
|
||||
|
||||
- (BOOL)mayHaveLinkedDevices:(YapDatabaseConnection *)dbConnection
|
||||
{
|
||||
OWSAssert(dbConnection);
|
||||
|
||||
@synchronized(self)
|
||||
{
|
||||
if (!self.mayHaveLinkedDevicesCached) {
|
||||
self.mayHaveLinkedDevicesCached = @([dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices
|
||||
inCollection:kTSStorageManager_OWSDeviceCollection
|
||||
defaultValue:YES]);
|
||||
}
|
||||
|
||||
return [self.mayHaveLinkedDevicesCached boolValue];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
{
|
||||
OWSAssert(dbConnection);
|
||||
|
||||
@synchronized(self)
|
||||
{
|
||||
self.mayHaveLinkedDevicesCached = @(YES);
|
||||
|
||||
[dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction setObject:@(value)
|
||||
forKey:kTSStorageManager_MayHaveLinkedDevices
|
||||
inCollection:kTSStorageManager_OWSDeviceCollection];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSDevice ()
|
||||
|
||||
@property (nonatomic) NSInteger deviceId;
|
||||
|
@ -182,26 +243,6 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
|
|||
return self.deviceId == device.deviceId;
|
||||
}
|
||||
|
||||
#pragma mark - "May Have Linked Devices" Flag
|
||||
|
||||
+ (BOOL)mayHaveLinkedDevices:(YapDatabaseConnection *)dbConnection
|
||||
{
|
||||
OWSAssert(dbConnection);
|
||||
|
||||
return [dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices
|
||||
inCollection:kTSStorageManager_OWSDeviceCollection
|
||||
defaultValue:YES];
|
||||
}
|
||||
|
||||
+ (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
{
|
||||
OWSAssert(dbConnection);
|
||||
|
||||
[dbConnection setBool:value
|
||||
forKey:kTSStorageManager_MayHaveLinkedDevices
|
||||
inCollection:kTSStorageManager_OWSDeviceCollection];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -971,7 +971,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
// devices, then can safely skip sending sync message.
|
||||
|
||||
// 1. Check OWSDevice's state.
|
||||
BOOL mayHaveLinkedDevices = [OWSDevice mayHaveLinkedDevices:self.dbConnection];
|
||||
BOOL mayHaveLinkedDevices = [OWSDeviceManager.sharedManager mayHaveLinkedDevices:self.dbConnection];
|
||||
|
||||
// 2. Check SignalRecipient's state.
|
||||
BOOL hasDeviceMessages = deviceMessages.count > 0;
|
||||
|
@ -1113,7 +1113,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
if (missingDevices.count > 0) {
|
||||
NSString *localNumber = [TSAccountManager localNumber];
|
||||
if ([localNumber isEqualToString:recipient.uniqueId]) {
|
||||
[OWSDevice setMayHaveLinkedDevices:YES dbConnection:self.dbConnection];
|
||||
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES dbConnection:self.dbConnection];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,8 +57,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (BOOL)boolForKey:(NSString *)key inCollection:(NSString *)collection defaultValue:(BOOL)defaultValue
|
||||
{
|
||||
NSNumber *_Nullable number = [self objectForKey:key inCollection:collection ofExpectedType:[NSNumber class]];
|
||||
return [number boolValue];
|
||||
NSNumber *_Nullable value = [self objectForKey:key inCollection:collection ofExpectedType:[NSNumber class]];
|
||||
return value ? [value boolValue] : defaultValue;
|
||||
}
|
||||
|
||||
- (nullable NSData *)dataForKey:(NSString *)key inCollection:(NSString *)collection
|
||||
|
|
Loading…
Reference in New Issue