Sync contacts after rotating profile key.

pull/1/head
Matthew Chen 7 years ago
parent eb7abdfc64
commit 8fdf6009f9

@ -1041,7 +1041,7 @@ static NSTimeInterval launchStartedAt;
[AppVersion.sharedInstance mainAppLaunchDidComplete];
[Environment.shared.contactsManager loadSignalAccountsFromCache];
[Environment.shared.contactsManager setup];
[Environment.shared.contactsManager startObserving];
// If there were any messages in our local queue which we hadn't yet processed.

@ -44,7 +44,7 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
- (SignalAccount *)fetchOrBuildSignalAccountForRecipientId:(NSString *)recipientId;
- (BOOL)hasSignalAccountForRecipientId:(NSString *)recipientId;
- (void)loadSignalAccountsFromCache;
- (void)setup;
#pragma mark - System Contact Fetching
@ -55,6 +55,8 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
@property (nonatomic, readonly) BOOL supportsContactEditing;
@property (atomic, readonly) BOOL isSetup;
// Request systems contacts and start syncing changes. The user will see an alert
// if they haven't previously.
- (void)requestSystemContactsOnce;

@ -48,6 +48,7 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
@property (nonatomic, readonly) YapDatabaseConnection *dbWriteConnection;
@property (nonatomic, readonly) NSCache<NSString *, CNContact *> *cnContactCache;
@property (nonatomic, readonly) NSCache<NSString *, UIImage *> *cnContactAvatarCache;
@property (atomic) BOOL isSetup;
@end
@ -84,8 +85,7 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
return self;
}
- (void)loadSignalAccountsFromCache
{
- (void)setup {
__block NSMutableArray<SignalAccount *> *signalAccounts;
[self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
NSUInteger signalAccountCount = [SignalAccount numberOfKeysInCollectionWithTransaction:transaction];
@ -571,6 +571,8 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
self.signalAccounts = [signalAccounts copy];
[self.profileManager setContactRecipientIds:signalAccountMap.allKeys];
self.isSetup = YES;
[[NSNotificationCenter defaultCenter]
postNotificationNameAsync:OWSContactsManagerSignalAccountsDidChangeNotification
object:nil];

@ -79,6 +79,10 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
selector:@selector(signalAccountsDidChange:)
name:OWSContactsManagerSignalAccountsDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(profileKeyDidChange:)
name:kNSNotificationName_ProfileKeyDidChange
object:nil];
return self;
}
@ -95,6 +99,12 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
[self sendSyncContactsMessageIfPossible];
}
- (void)profileKeyDidChange:(id)notification {
OWSAssertIsOnMainThread();
[self sendSyncContactsMessageIfPossible];
}
- (YapDatabaseConnection *)editingDatabaseConnection
{
return OWSPrimaryStorage.sharedManager.dbReadWriteConnection;
@ -172,9 +182,9 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
- (void)sendSyncContactsMessageIfPossible
{
OWSAssertIsOnMainThread();
if (self.contactsManager.signalAccounts.count == 0) {
// Don't bother if the contacts manager has no contacts,
// e.g. if the contacts manager hasn't finished setup.
if (!self.contactsManager.isSetup) {
// Don't bother if the contacts manager hasn't finished setup.
return;
}

@ -7,6 +7,7 @@
NS_ASSUME_NONNULL_BEGIN
extern NSString *const kNSNotificationName_ProfileWhitelistDidChange;
extern NSString *const kNSNotificationName_ProfileKeyDidChange;
extern const NSUInteger kOWSProfileManager_NameDataLength;
extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;

@ -39,6 +39,8 @@ NSString *const kNSNotificationName_ProfileWhitelistDidChange = @"kNSNotificatio
NSString *const kOWSProfileManager_UserWhitelistCollection = @"kOWSProfileManager_UserWhitelistCollection";
NSString *const kOWSProfileManager_GroupWhitelistCollection = @"kOWSProfileManager_GroupWhitelistCollection";
NSString *const kNSNotificationName_ProfileKeyDidChange = @"kNSNotificationName_ProfileKeyDidChange";
// The max bytes for a user's profile name, encoded in UTF8.
// Before encrypting and submitting we NULL pad the name data to this length.
const NSUInteger kOWSProfileManager_NameDataLength = 26;
@ -731,6 +733,10 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
});
promise = promise.then(^(id value) {
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_ProfileKeyDidChange
object:nil
userInfo:nil];
success();
});
promise = promise.catch(^(NSError *error) {

@ -265,7 +265,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
AppVersion.sharedInstance().saeLaunchDidComplete()
Environment.shared.contactsManager.loadSignalAccountsFromCache()
Environment.shared.contactsManager.setup()
Environment.shared.contactsManager.startObserving()
ensureRootViewController()

Loading…
Cancel
Save