From 055061ff5e34ed2df6203a83bb4d01a91aeb3a8f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 28 Feb 2018 22:50:02 -0500 Subject: [PATCH] Clean up ahead of PR. --- .../OWS2FASettingsViewController.m | 32 +++++++++++++------ SignalServiceKit/src/Util/OWS2FAManager.h | 2 ++ SignalServiceKit/src/Util/OWS2FAManager.m | 7 ++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Signal/src/ViewControllers/OWS2FASettingsViewController.m b/Signal/src/ViewControllers/OWS2FASettingsViewController.m index 611d7d5af..b91066c33 100644 --- a/Signal/src/ViewControllers/OWS2FASettingsViewController.m +++ b/Signal/src/ViewControllers/OWS2FASettingsViewController.m @@ -38,6 +38,16 @@ NS_ASSUME_NONNULL_BEGIN self.title = NSLocalizedString(@"ENABLE_2FA_VIEW_TITLE", @"Title for the 'enable two factor auth PIN' views."); [self createContents]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(stateDidChange:) + name:NSNotificationName_2FAStateDidChange + object:nil]; +} + +- (void)dealloc +{ + [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)createContents @@ -72,15 +82,8 @@ NS_ASSUME_NONNULL_BEGIN [super viewWillAppear:animated]; - if (self.mode == OWS2FASettingsMode_Status) { - // Ever time we re-enter the "status" view, recreate its - // contents wholesale since we may have just enabled or - // disabled 2FA. - [self createContents]; - } else { - // If we're using a table, refresh its contents. - [self updateTableContents]; - } + // If we're using a table, refresh its contents. + [self updateTableContents]; [self updateNavigationItems]; } @@ -413,7 +416,7 @@ NS_ASSUME_NONNULL_BEGIN } failure:^(NSError *error) { [modalActivityIndicator dismissWithCompletion:^{ - [weakSelf createContents]; + [weakSelf updateTableContents]; [OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"") @@ -477,6 +480,15 @@ NS_ASSUME_NONNULL_BEGIN [self.navigationController popViewControllerAnimated:YES]; } +- (void)stateDidChange:(NSNotification *)notification +{ + DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); + + if (self.mode == OWS2FASettingsMode_Status) { + [self createContents]; + } +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/OWS2FAManager.h b/SignalServiceKit/src/Util/OWS2FAManager.h index 71f15db86..9a2828b64 100644 --- a/SignalServiceKit/src/Util/OWS2FAManager.h +++ b/SignalServiceKit/src/Util/OWS2FAManager.h @@ -4,6 +4,8 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const NSNotificationName_2FAStateDidChange; + typedef void (^OWS2FASuccess)(void); typedef void (^OWS2FAFailure)(NSError *error); diff --git a/SignalServiceKit/src/Util/OWS2FAManager.m b/SignalServiceKit/src/Util/OWS2FAManager.m index 1be41697c..a886f2f2a 100644 --- a/SignalServiceKit/src/Util/OWS2FAManager.m +++ b/SignalServiceKit/src/Util/OWS2FAManager.m @@ -3,6 +3,7 @@ // #import "OWS2FAManager.h" +#import "NSNotificationCenter+OWS.h" #import "OWSRequestFactory.h" #import "TSNetworkManager.h" #import "TSStorageManager.h" @@ -10,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN +NSString *const NSNotificationName_2FAStateDidChange = @"NSNotificationName_2FAStateDidChange"; + NSString *const kOWS2FAManager_Collection = @"kOWS2FAManager_Collection"; NSString *const kOWS2FAManager_IsEnabledKey = @"kOWS2FAManager_IsEnabledKey"; @@ -72,6 +75,10 @@ NSString *const kOWS2FAManager_IsEnabledKey = @"kOWS2FAManager_IsEnabledKey"; - (void)setIs2FAEnabled:(BOOL)value { [self.dbConnection setBool:value forKey:kOWS2FAManager_IsEnabledKey inCollection:kOWS2FAManager_Collection]; + + [[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationName_2FAStateDidChange + object:nil + userInfo:nil]; } - (void)enable2FAWithPin:(NSString *)pin success:(nullable OWS2FASuccess)success failure:(nullable OWS2FAFailure)failure