Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 04b3166b85
commit aa3402b535

@ -271,7 +271,12 @@ NSString *const kNSNotificationName_RegistrationStateDidChange = @"kNSNotificati
DDLogInfo(@"%@ Successfully unregistered", self.tag); DDLogInfo(@"%@ Successfully unregistered", self.tag);
success(); success();
// The success handler should reset local storage. // This is called from `[SettingsTableViewController proceedToUnregistration]` whose
// success handler calls `[Environment resetAppData]`.
// This method, after calling that success handler, fires
// `kNSNotificationName_RegistrationStateDidChange` which is only safe to fire after
// the data store is reset.
[[NSNotificationCenter defaultCenter] postNotificationName:kNSNotificationName_RegistrationStateDidChange [[NSNotificationCenter defaultCenter] postNotificationName:kNSNotificationName_RegistrationStateDidChange
object:nil object:nil
userInfo:nil]; userInfo:nil];

@ -83,6 +83,8 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification";
// notification. // notification.
@property (nonatomic) BOOL appIsActive; @property (nonatomic) BOOL appIsActive;
@property (nonatomic) BOOL hasObservedNotifications;
@end @end
#pragma mark - #pragma mark -
@ -105,6 +107,27 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification";
[self addObserver:self forKeyPath:@"status" options:0 context:kSocketStatusObservationContext]; [self addObserver:self forKeyPath:@"status" options:0 context:kSocketStatusObservationContext];
OWSSingletonAssert();
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
// We want to observe these notifications lazily to avoid accessing
// the data store in [application: didFinishLaunchingWithOptions:].
- (void)observeNotificationsIfNecessary
{
if (self.hasObservedNotifications) {
return;
}
self.hasObservedNotifications = YES;
self.appIsActive = [UIApplication sharedApplication].applicationState == UIApplicationStateActive;
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive:) selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification name:UIApplicationDidBecomeActiveNotification
@ -117,15 +140,6 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification";
selector:@selector(registrationStateDidChange:) selector:@selector(registrationStateDidChange:)
name:kNSNotificationName_RegistrationStateDidChange name:kNSNotificationName_RegistrationStateDidChange
object:nil]; object:nil];
OWSSingletonAssert();
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
} }
+ (instancetype)sharedManager { + (instancetype)sharedManager {
@ -461,11 +475,6 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification";
[TSStorageManager serverAuthToken]]; [TSStorageManager serverAuthToken]];
} }
- (void)setFetchingTaskIdentifier:(UIBackgroundTaskIdentifier)fetchingTaskIdentifier
{
_fetchingTaskIdentifier = fetchingTaskIdentifier;
}
#pragma mark UI Delegates #pragma mark UI Delegates
- (void)observeValueForKeyPath:(NSString *)keyPath - (void)observeValueForKeyPath:(NSString *)keyPath
@ -590,6 +599,8 @@ NSString *const SocketConnectingNotification = @"SocketConnectingNotification";
+ (void)requestSocketOpen + (void)requestSocketOpen
{ {
DispatchMainThreadSafe(^{ DispatchMainThreadSafe(^{
[[self sharedManager] observeNotificationsIfNecessary];
// If the app is active and the user is registered, this will // If the app is active and the user is registered, this will
// simply open the websocket. // simply open the websocket.
// //

Loading…
Cancel
Save