From 04bf548a7b33908159e59bf39c7b261b2850d023 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 7 Sep 2017 10:28:19 -0400 Subject: [PATCH] Fix one-time crash when opening thread without having a local profile // FREEBIE --- Signal/src/AppDelegate.m | 1 + Signal/src/Profiles/OWSProfileManager.h | 1 + Signal/src/Profiles/OWSProfileManager.m | 8 +++++++- Signal/src/ViewControllers/SignalsViewController.m | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index e43f4fb77..9a3509083 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -473,6 +473,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // Clean up any messages that expired since last launch immediately // and continue cleaning in the background. [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; + [[OWSProfileManager sharedManager] ensureLocalProfileCached]; // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully // sent before the app exited should be marked as failures. diff --git a/Signal/src/Profiles/OWSProfileManager.h b/Signal/src/Profiles/OWSProfileManager.h index d6d070a56..4f6982dfc 100644 --- a/Signal/src/Profiles/OWSProfileManager.h +++ b/Signal/src/Profiles/OWSProfileManager.h @@ -36,6 +36,7 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; - (BOOL)hasLocalProfile; - (nullable NSString *)localProfileName; - (nullable UIImage *)localProfileAvatarImage; +- (void)ensureLocalProfileCached; // This method is used to update the "local profile" state on the client // and the service. Client state is only updated if service state is diff --git a/Signal/src/Profiles/OWSProfileManager.m b/Signal/src/Profiles/OWSProfileManager.m index 19792a5c6..a96b6eba1 100644 --- a/Signal/src/Profiles/OWSProfileManager.m +++ b/Signal/src/Profiles/OWSProfileManager.m @@ -270,6 +270,13 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; } } +- (void)ensureLocalProfileCached +{ + // Since localUserProfile can create a transaction, we want to make sure it's not called for the first + // time unexpectedly (e.g. in a nested transaction.) + __unused UserProfile *profile = [self localUserProfile]; +} + #pragma mark - Local Profile - (UserProfile *)localUserProfile @@ -652,7 +659,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; }); } -// TODO: The exact API & encryption scheme for profiles is not yet settled. - (void)updateServiceWithProfileName:(nullable NSString *)localProfileName success:(void (^)())successBlock failure:(void (^)())failureBlock diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 452533867..08d82372b 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -11,6 +11,7 @@ #import "NSDate+millisecondTimeStamp.h" #import "OWSContactsManager.h" #import "OWSNavigationController.h" +#import "OWSProfileManager.h" #import "ProfileViewController.h" #import "PropertyListPreferences.h" #import "PushManager.h" @@ -491,6 +492,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; // Start running the disappearing messages job in case the newly registered user // enables this feature [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; + [[OWSProfileManager sharedManager] ensureLocalProfileCached]; } else if (!self.viewHasEverAppeared) { [self displayAnyUnseenUpgradeExperience]; }