Re-register without losing your messages in Debug-UI

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 83357a0fe4
commit 58d4c95362

@ -6,6 +6,7 @@
#import "Environment.h"
#import "OWSCountryMetadata.h"
#import "OWSTableViewController.h"
#import "RegistrationViewController.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <AFNetworking/AFNetworking.h>
@ -21,6 +22,12 @@
NS_ASSUME_NONNULL_BEGIN
@interface TSAccountManager (Debug)
- (void)resetForRegistration;
@end
@implementation DebugUIMisc
#pragma mark - Logging
@ -61,6 +68,41 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{
[DebugUIMisc clearHasDismissedOffers];
}]];
[items addObject:[OWSTableItem
itemWithTitle:@"Re-register"
actionBlock:^{
[OWSAlerts
showConfirmationAlertWithTitle:@"Re-register?"
message:@"If you proceed, you will not lose any of your "
@"current messages, but your account will be "
@"deactivated until you complete re-registration."
proceedTitle:@"Proceed"
proceedAction:^(UIAlertAction *_Nonnull action) {
DDLogError(@"Re-registering.");
[[TSAccountManager sharedInstance] resetForRegistration];
OWSSyncPushTokensJob *syncPushTokensJob = [
[OWSSyncPushTokensJob alloc]
initWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager
preferences:[Environment getCurrent].preferences];
syncPushTokensJob.uploadOnlyIfStale = NO;
__unused id promise = [syncPushTokensJob run];
RegistrationViewController *viewController =
[RegistrationViewController new];
OWSNavigationController *navigationController =
[[OWSNavigationController alloc]
initWithRootViewController:viewController];
navigationController.navigationBarHidden = YES;
[UIApplication sharedApplication]
.delegate.window.rootViewController
= navigationController;
}];
}]];
return [OWSTableSection sectionWithTitle:self.name items:items];
}

@ -74,7 +74,7 @@ class SafetyNumberConfirmationAlert: NSObject {
}
actionSheetController.addAction(showSafetyNumberAction)
actionSheetController.addAction(OWSAlerts.cancelAction())
actionSheetController.addAction(OWSAlerts.cancelAction)
UIApplication.shared.frontmostViewController?.present(actionSheetController, animated: true)
return true

@ -33,14 +33,26 @@ import Foundation
public class func showAlert(withTitle title: String, message: String? = nil, buttonTitle: String? = nil) {
assert(title.characters.count > 0)
let actionTitle = (buttonTitle != nil ? buttonTitle : NSLocalizedString("OK", comment: ""))
let actionTitle = buttonTitle ?? NSLocalizedString("OK", comment: "")
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: actionTitle, style: .default, handler: nil))
UIApplication.shared.frontmostViewController?.present(alert, animated: true, completion: nil)
}
public class func cancelAction() -> UIAlertAction {
public class func showConfirmationAlert(withTitle title: String, message: String? = nil, proceedTitle: String? = nil, proceedAction: @escaping (UIAlertAction) -> Void) {
assert(title.characters.count > 0)
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(self.cancelAction)
let actionTitle = proceedTitle ?? NSLocalizedString("OK", comment: "")
alert.addAction(UIAlertAction(title: actionTitle, style: .default, handler: proceedAction))
UIApplication.shared.frontmostViewController?.present(alert, animated: true, completion: nil)
}
public class var cancelAction: UIAlertAction {
let action = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in
Logger.debug("Cancel item")
// Do nothing.

@ -12,6 +12,7 @@
#import "TSNetworkManager.h"
#import "TSPreKeyManager.h"
#import "TSSocketManager.h"
#import "TSStorageManager+SessionStore.h"
#import "TSStorageManager+keyingMaterial.h"
NS_ASSUME_NONNULL_BEGIN
@ -76,6 +77,18 @@ NSString *const TSAccountManager_LocalRegistrationIdKey = @"TSStorageLocalRegist
userInfo:nil];
}
- (void)resetForRegistration
{
@synchronized(self)
{
_isRegistered = NO;
_cachedLocalNumber = nil;
_phoneNumberAwaitingVerification = nil;
[self removeStoredLocalNumber];
}
[[TSStorageManager sharedManager] resetSessionStore];
}
+ (BOOL)isRegistered
{
return [[self sharedInstance] isRegistered];
@ -137,6 +150,15 @@ NSString *const TSAccountManager_LocalRegistrationIdKey = @"TSStorageLocalRegist
return self.cachedLocalNumber;
}
- (void)removeStoredLocalNumber
{
@synchronized(self)
{
[self.dbConnection removeObjectForKey:TSAccountManager_RegisteredNumberKey
inCollection:TSStorageUserAccountCollection];
}
}
- (nullable NSString *)storedLocalNumber
{
@synchronized (self) {

@ -11,6 +11,7 @@
#pragma mark - debug
- (void)resetSessionStore;
- (void)printAllSessions;
@end

@ -189,6 +189,14 @@ void AssertIsOnSessionStoreQueue()
#pragma mark - debug
- (void)resetSessionStore
{
DDLogWarn(@"%@ resetting session store", self.tag);
[self.sessionDBConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[transaction removeAllObjectsInCollection:TSStorageManagerSessionStoreCollection];
}];
}
- (void)printAllSessions
{
AssertIsOnSessionStoreQueue();

Loading…
Cancel
Save