diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 621748693..f36a8686f 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -736,7 +736,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [AppVersion.instance appLaunchDidComplete]; [Environment.current.contactsManager loadSignalAccountsFromCache]; - + [self ensureRootViewController]; // If there were any messages in our local queue which we hadn't yet processed. diff --git a/SignalMessaging/contacts/OWSContactsManager.m b/SignalMessaging/contacts/OWSContactsManager.m index 7b6394349..f333411ed 100644 --- a/SignalMessaging/contacts/OWSContactsManager.m +++ b/SignalMessaging/contacts/OWSContactsManager.m @@ -49,17 +49,17 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification // TODO: We need to configure the limits of this cache. _avatarCache = [ImageCache new]; - + _dbReadConnection = [TSStorageManager sharedManager].newDatabaseConnection; _dbWriteConnection = [TSStorageManager sharedManager].newDatabaseConnection; - + _allContacts = @[]; _allContactsMap = @{}; _signalAccountMap = @{}; _signalAccounts = @[]; _systemContactsFetcher = [SystemContactsFetcher new]; _systemContactsFetcher.delegate = self; - + OWSSingletonAssert(); return self; @@ -68,14 +68,16 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification - (void)loadSignalAccountsFromCache { __block NSMutableArray *signalAccounts; - [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) { - signalAccounts = [[NSMutableArray alloc] initWithCapacity:[SignalAccount numberOfKeysInCollectionWithTransaction:transaction]]; - - [SignalAccount enumerateCollectionObjectsWithTransaction:transaction usingBlock:^(SignalAccount *signalAccount, BOOL * _Nonnull stop) { - [signalAccounts addObject:signalAccount]; - }]; + [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + signalAccounts = [[NSMutableArray alloc] + initWithCapacity:[SignalAccount numberOfKeysInCollectionWithTransaction:transaction]]; + + [SignalAccount enumerateCollectionObjectsWithTransaction:transaction + usingBlock:^(SignalAccount *signalAccount, BOOL *_Nonnull stop) { + [signalAccounts addObject:signalAccount]; + }]; }]; - + [self updateSignalAccounts:signalAccounts]; } @@ -253,14 +255,14 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification [orphanedKeys removeObject:signalAccount.uniqueId]; [signalAccount saveWithTransaction:transaction]; } - + if (orphanedKeys.count > 0) { DDLogInfo(@"%@ Removing %lu orphaned SignalAccounts", self.logTag, (unsigned long)orphanedKeys.count); [transaction removeObjectsForKeys:orphanedKeys.allObjects inCollection:[SignalAccount collection]]; } }]; - + dispatch_async(dispatch_get_main_queue(), ^{ [self updateSignalAccounts:signalAccounts]; }); @@ -270,12 +272,12 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification - (void)updateSignalAccounts:(NSArray *)signalAccounts { AssertIsOnMainThread(); - + NSMutableDictionary *signalAccountMap = [NSMutableDictionary new]; for (SignalAccount *signalAccount in signalAccounts) { signalAccountMap[signalAccount.recipientId] = signalAccount; } - + self.signalAccountMap = [signalAccountMap copy]; self.signalAccounts = [signalAccounts copy]; [self.profileManager setContactRecipientIds:signalAccountMap.allKeys]; @@ -593,8 +595,8 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification // If contact intersection hasn't completed, it might exist on disk // even if it doesn't exist in memory yet. if (!signalAccount) { - [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) { - signalAccount = [SignalAccount fetchObjectWithUniqueID:recipientId transaction: transaction]; + [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + signalAccount = [SignalAccount fetchObjectWithUniqueID:recipientId transaction:transaction]; }]; } diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index f365b83f8..650b04290 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -194,23 +194,22 @@ public class ShareViewController: UINavigationController, ShareViewDelegate, SAE // TODO: Should we distinguish main app and SAE "completion"? AppVersion.instance().appLaunchDidComplete() - + Environment.current().contactsManager.loadSignalAccountsFromCache() - + ensureRootViewController() // We don't need to use OWSMessageReceiver in the SAE. // We don't need to use OWSBatchMessageProcessor in the SAE. OWSProfileManager.shared().ensureLocalProfileCached() - + // We don't need to use OWSOrphanedDataCleaner in the SAE. OWSProfileManager.shared().fetchLocalUsersProfile() OWSReadReceiptManager.shared().prepareCachedValues() - } @objc