Show push tokens in about view.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-11-17 18:04:20 -05:00
parent 9b14c77775
commit 6e60d99ecf
2 changed files with 34 additions and 0 deletions

View file

@ -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<Void> {
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: ())

View file

@ -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 <SignalServiceKit/TSDatabaseView.h>
@ -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;