Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent c308e25115
commit d81d85c386

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSLinkDeviceViewController.h"
@ -147,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)provisionWithParser:(OWSDeviceProvisioningURLParser *)parser
{
// Optimistically set this flag.
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES dbConnection:self.dbConnection];
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
ECKeyPair *_Nullable identityKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair];
OWSAssert(identityKeyPair);

@ -146,9 +146,7 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1;
if (devices.count > 1) {
// Setting this flag here shouldn't be necessary, but we do so
// because the "cost" is low and it will improve robustness.
[OWSDeviceManager.sharedManager
setMayHaveLinkedDevices:YES
dbConnection:[[TSStorageManager sharedManager] newDatabaseConnection]];
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
}
if (devices.count > [OWSDevice numberOfKeysInCollection]) {

@ -16,8 +16,7 @@ extern uint32_t const OWSDevicePrimaryDeviceId;
+ (instancetype)sharedManager;
- (BOOL)mayHaveLinkedDevices:(YapDatabaseConnection *)dbConnection;
- (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection;
- (void)setMayHaveLinkedDevices:(BOOL)value transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)setMayHaveLinkedDevices;
- (BOOL)hasReceivedSyncMessageInLastSeconds:(NSTimeInterval)intervalSeconds;
- (void)setHasReceivedSyncMessage;

@ -19,6 +19,7 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
@interface OWSDeviceManager ()
@property (atomic, nullable) NSNumber *mayHaveLinkedDevicesCached;
@property (atomic) NSDate *lastReceivedSyncMessage;
@end
@ -46,27 +47,32 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
{
OWSAssert(dbConnection);
return [dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection
defaultValue:NO];
}
- (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection
{
OWSAssert(dbConnection);
// We don't bother synchronizing around
if (!self.mayHaveLinkedDevicesCached) {
self.mayHaveLinkedDevicesCached = @([dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection
defaultValue:YES]);
}
[dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[self setMayHaveLinkedDevices:value transaction:transaction];
}];
return [self.mayHaveLinkedDevicesCached boolValue];
}
- (void)setMayHaveLinkedDevices:(BOOL)value transaction:(YapDatabaseReadWriteTransaction *)transaction
- (void)setMayHaveLinkedDevices
{
OWSAssert(transaction);
if (self.mayHaveLinkedDevicesCached != nil && self.mayHaveLinkedDevicesCached.boolValue) {
// Skip redundant writes.
return;
}
[transaction setObject:@(value)
forKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection];
self.mayHaveLinkedDevicesCached = @(YES);
// Note that we write async to avoid opening transactions within transactions.
[TSStorageManager.sharedManager.newDatabaseConnection
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction setObject:@(YES)
forKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection];
}];
}
- (BOOL)hasReceivedSyncMessageInLastSeconds:(NSTimeInterval)intervalSeconds
@ -77,6 +83,8 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
- (void)setHasReceivedSyncMessage
{
self.lastReceivedSyncMessage = [NSDate new];
[self setMayHaveLinkedDevices];
}
@end

@ -278,7 +278,6 @@ NS_ASSUME_NONNULL_BEGIN
[self handleIncomingEnvelope:envelope withSyncMessage:content.syncMessage transaction:transaction];
[[OWSDeviceManager sharedManager] setHasReceivedSyncMessage];
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES transaction:transaction];
} else if (content.hasDataMessage) {
[self handleIncomingEnvelope:envelope withDataMessage:content.dataMessage transaction:transaction];
} else if (content.hasCallMessage) {

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSMessageSender.h"
@ -1090,7 +1090,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if (missingDevices.count > 0) {
NSString *localNumber = [TSAccountManager localNumber];
if ([localNumber isEqualToString:recipient.uniqueId]) {
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES dbConnection:self.dbConnection];
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
}
}

Loading…
Cancel
Save