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" #import "OWSLinkDeviceViewController.h"
@ -147,7 +147,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)provisionWithParser:(OWSDeviceProvisioningURLParser *)parser - (void)provisionWithParser:(OWSDeviceProvisioningURLParser *)parser
{ {
// Optimistically set this flag. // Optimistically set this flag.
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES dbConnection:self.dbConnection]; [OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
ECKeyPair *_Nullable identityKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair]; ECKeyPair *_Nullable identityKeyPair = [[OWSIdentityManager sharedManager] identityKeyPair];
OWSAssert(identityKeyPair); OWSAssert(identityKeyPair);

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

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

@ -19,6 +19,7 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
@interface OWSDeviceManager () @interface OWSDeviceManager ()
@property (atomic, nullable) NSNumber *mayHaveLinkedDevicesCached;
@property (atomic) NSDate *lastReceivedSyncMessage; @property (atomic) NSDate *lastReceivedSyncMessage;
@end @end
@ -46,27 +47,32 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
{ {
OWSAssert(dbConnection); OWSAssert(dbConnection);
return [dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices // We don't bother synchronizing around
inCollection:kTSStorageManager_OWSDeviceCollection if (!self.mayHaveLinkedDevicesCached) {
defaultValue:NO]; self.mayHaveLinkedDevicesCached = @([dbConnection boolForKey:kTSStorageManager_MayHaveLinkedDevices
} inCollection:kTSStorageManager_OWSDeviceCollection
defaultValue:YES]);
- (void)setMayHaveLinkedDevices:(BOOL)value dbConnection:(YapDatabaseConnection *)dbConnection }
{
OWSAssert(dbConnection);
[dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { return [self.mayHaveLinkedDevicesCached boolValue];
[self setMayHaveLinkedDevices:value transaction:transaction];
}];
} }
- (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) self.mayHaveLinkedDevicesCached = @(YES);
forKey:kTSStorageManager_MayHaveLinkedDevices
inCollection:kTSStorageManager_OWSDeviceCollection]; // 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 - (BOOL)hasReceivedSyncMessageInLastSeconds:(NSTimeInterval)intervalSeconds
@ -77,6 +83,8 @@ NSString *const kTSStorageManager_MayHaveLinkedDevices = @"kTSStorageManager_May
- (void)setHasReceivedSyncMessage - (void)setHasReceivedSyncMessage
{ {
self.lastReceivedSyncMessage = [NSDate new]; self.lastReceivedSyncMessage = [NSDate new];
[self setMayHaveLinkedDevices];
} }
@end @end

@ -278,7 +278,6 @@ NS_ASSUME_NONNULL_BEGIN
[self handleIncomingEnvelope:envelope withSyncMessage:content.syncMessage transaction:transaction]; [self handleIncomingEnvelope:envelope withSyncMessage:content.syncMessage transaction:transaction];
[[OWSDeviceManager sharedManager] setHasReceivedSyncMessage]; [[OWSDeviceManager sharedManager] setHasReceivedSyncMessage];
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES transaction:transaction];
} else if (content.hasDataMessage) { } else if (content.hasDataMessage) {
[self handleIncomingEnvelope:envelope withDataMessage:content.dataMessage transaction:transaction]; [self handleIncomingEnvelope:envelope withDataMessage:content.dataMessage transaction:transaction];
} else if (content.hasCallMessage) { } 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" #import "OWSMessageSender.h"
@ -1090,7 +1090,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if (missingDevices.count > 0) { if (missingDevices.count > 0) {
NSString *localNumber = [TSAccountManager localNumber]; NSString *localNumber = [TSAccountManager localNumber];
if ([localNumber isEqualToString:recipient.uniqueId]) { if ([localNumber isEqualToString:recipient.uniqueId]) {
[OWSDeviceManager.sharedManager setMayHaveLinkedDevices:YES dbConnection:self.dbConnection]; [OWSDeviceManager.sharedManager setMayHaveLinkedDevices];
} }
} }

Loading…
Cancel
Save