From 6e60d99ecf756de0a7e8e7a7c91dbc8460280f8f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 17 Nov 2017 18:04:20 -0500 Subject: [PATCH] Show push tokens in about view. // FREEBIE --- Signal/src/Models/SyncPushTokensJob.swift | 12 ++++++++++ .../AboutTableViewController.m | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Signal/src/Models/SyncPushTokensJob.swift b/Signal/src/Models/SyncPushTokensJob.swift index 9eadb7699..68d8bfebe 100644 --- a/Signal/src/Models/SyncPushTokensJob.swift +++ b/Signal/src/Models/SyncPushTokensJob.swift @@ -8,6 +8,8 @@ import PromiseKit class SyncPushTokensJob: NSObject { let TAG = "[SyncPushTokensJob]" + @objc public static let PushTokensDidChange = Notification.Name("PushTokensDidChange") + // MARK: Dependencies let accountManager: AccountManager let preferences: OWSPreferences @@ -90,14 +92,24 @@ class SyncPushTokensJob: NSObject { private func recordPushTokensLocally(pushToken: String, voipToken: String) -> Promise { Logger.warn("\(TAG) Recording push tokens locally. pushToken: \(pushToken), voipToken: \(voipToken)") + var didTokensChange = false + if (pushToken != self.preferences.getPushToken()) { Logger.info("\(TAG) Recording new plain push token") self.preferences.setPushToken(pushToken) + didTokensChange = true } if (voipToken != self.preferences.getVoipToken()) { Logger.info("\(TAG) Recording new voip token") self.preferences.setVoipToken(voipToken) + didTokensChange = true + } + + if (didTokensChange) { + DispatchQueue.main.async { + NotificationCenter.default.post(name: SyncPushTokensJob.PushTokensDidChange, object: nil) + } } return Promise(value: ()) diff --git a/Signal/src/ViewControllers/AboutTableViewController.m b/Signal/src/ViewControllers/AboutTableViewController.m index 4aac70d56..aa031e6b9 100644 --- a/Signal/src/ViewControllers/AboutTableViewController.m +++ b/Signal/src/ViewControllers/AboutTableViewController.m @@ -3,6 +3,9 @@ // #import "AboutTableViewController.h" +#import "Environment.h" +#import "OWSPreferences.h" +#import "Signal-Swift.h" #import "UIUtil.h" #import "UIView+OWS.h" #import @@ -10,6 +13,10 @@ @implementation AboutTableViewController +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + - (void)viewDidLoad { [super viewDidLoad]; @@ -17,6 +24,15 @@ self.title = NSLocalizedString(@"SETTINGS_ABOUT", @"Navbar title"); [self updateTableContents]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(pushTokensDidChange:) + name:[OWSSyncPushTokensJob PushTokensDidChange] + object:nil]; +} + +- (void)pushTokensDidChange:(NSNotification *)notification { + [self updateTableContents]; } #pragma mark - Table Contents @@ -64,6 +80,12 @@ [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Threads: %zd", threadCount]]]; [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Messages: %zd", messageCount]]]; [contents addSection:debugSection]; + + OWSPreferences *preferences = [Environment preferences]; + NSString *_Nullable pushToken = [preferences getPushToken]; + NSString *_Nullable voipToken = [preferences getVoipToken]; + [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"Push Token: %@", pushToken ?: @"None" ]]]; + [debugSection addItem:[OWSTableItem labelItemWithText:[NSString stringWithFormat:@"VOIP Token: %@", voipToken ?: @"None" ]]]; #endif self.contents = contents;