Fixing issue when migration closed and re-opened.

pull/1/head
Frederic Jacobs 10 years ago
parent 311a758d27
commit 24616735e5

@ -45,13 +45,14 @@ static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
#pragma mark Detect updates - perform migrations
- (void)performUpdateCheck{
NSString *previousVersion = Environment.preferences.lastRanVersion;
NSString *currentVersion = [Environment.preferences setAndGetCurrentVersion];
NSString *previousVersion = Environment.preferences.lastRanVersion;
NSString *currentVersion = [Environment.preferences setAndGetCurrentVersion];
BOOL isCurrentlyMigrating = [VersionMigrations isMigratingTo2Dot0];
if (!previousVersion) {
DDLogError(@"No previous version found. Possibly first launch since install.");
} else if(([self isVersion:previousVersion atLeast:@"1.0.2" andLessThan:@"2.0"]) || [Environment.preferences getIsMigratingToVersion2Dot0] ) {
[VersionMigrations migrateFrom1Dot0Dot2ToVersion2Dot0];
} else if(([self isVersion:previousVersion atLeast:@"1.0.2" andLessThan:@"2.0"]) || isCurrentlyMigrating) {
[VersionMigrations migrateFrom1Dot0Dot2ToVersion2Dot0];
}
}

@ -25,9 +25,6 @@ typedef NS_ENUM(NSUInteger, TSImageQuality) {
-(NSTimeInterval) getCachedOrDefaultDesiredBufferDepth;
-(void) setCachedDesiredBufferDepth:(double)value;
- (BOOL) getIsMigratingToVersion2Dot0;
- (void) setIsMigratingToVersion2Dot0:(BOOL)enabled;
- (BOOL) getHasSentAMessage;
- (void) setHasSentAMessage:(BOOL)enabled;

@ -25,7 +25,6 @@
#define DEBUG_IS_ENABLED_KEY @"Debugging Log Enabled Key"
#define NOTIFICATION_PREVIEW_TYPE_KEY @"Notification Preview Type Key"
#define IMAGE_UPLOAD_QUALITY_KEY @"Image Upload Quality Key"
#define IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY @"Migrating from 1.0 to Larger"
#define HAS_SENT_A_MESSAGE_KEY @"User has sent a message"
#define HAS_ARCHIVED_A_MESSAGE_KEY @"User archived a message"
#define kSignalVersionKey @"SignalUpdateVersionKey"
@ -103,16 +102,6 @@
}
}
- (BOOL) getIsMigratingToVersion2Dot0 {
NSNumber *preference = [self tryGetValueForKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY];
if (preference) {
return [preference boolValue];
} else{
return NO;
}
}
- (BOOL)loggingIsEnabled{
NSNumber *preference = [self tryGetValueForKey:DEBUG_IS_ENABLED_KEY];
if (preference) {
@ -209,10 +198,6 @@
return [NSUserDefaults.standardUserDefaults objectForKey:kSignalVersionKey];
}
- (void) setIsMigratingToVersion2Dot0:(BOOL)enabled {
[self setValueForKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY toValue:@(enabled)];
}
- (void) setHasSentAMessage:(BOOL)enabled{
[self setValueForKey:HAS_SENT_A_MESSAGE_KEY toValue:@(enabled)];
}

@ -14,4 +14,6 @@
+ (void)migrateFrom1Dot0Dot2ToVersion2Dot0;
+ (BOOL)isMigratingTo2Dot0;
@end

@ -19,6 +19,8 @@
#import "TSStorageManager.h"
#import "TSDatabaseView.h"
#define IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY @"Migrating from 1.0 to Larger"
@interface SignalKeyingStorage(VersionMigrations)
+(void)storeString:(NSString*)string forKey:(NSString*)key;
@ -29,13 +31,15 @@
+ (void)migrateFrom1Dot0Dot2ToVersion2Dot0 {
if (!([self wasRedPhoneRegistered] || [Environment.preferences getIsMigratingToVersion2Dot0])) {
if (!([self wasRedPhoneRegistered] || [self isMigratingTo2Dot0])) {
return;
}
[Environment.preferences setIsMigratingToVersion2Dot0:YES];
[self migrateRecentCallsToVersion2Dot0];
[self migrateKeyingStorageToVersion2Dot0];
if ([self wasRedPhoneRegistered]) {
[self migrateRecentCallsToVersion2Dot0];
[self migrateKeyingStorageToVersion2Dot0];
[self clearUserDefaults];
}
[UIApplication.sharedApplication setNetworkActivityIndicatorVisible:YES];
@ -43,14 +47,12 @@
message:nil
preferredStyle:UIAlertControllerStyleAlert];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:waitingController
animated:YES
completion:nil];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:waitingController animated:YES completion:nil];
[PushManager.sharedManager registrationAndRedPhoneTokenRequestWithSuccess:^(NSData *pushToken, NSString *signupToken) {
[TSAccountManager registerWithRedPhoneToken:signupToken pushToken:pushToken success:^{
[UIApplication.sharedApplication setNetworkActivityIndicatorVisible:NO];
[Environment.preferences setIsMigratingToVersion2Dot0:NO];
[self clearMigrationFlag];
Environment *env = [Environment getCurrent];
PhoneNumberDirectoryFilterManager *manager = [env phoneDirectoryManager];
[manager forceUpdate];
@ -96,15 +98,11 @@
for (RecentCall* recentCall in allRecents) {
[Environment.getCurrent.recentCallManager addRecentCall:recentCall];
}
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
}
}
+(BOOL)wasRedPhoneRegistered{
BOOL hasPassCounter = [UICKeyChainStore stringForKey:PASSWORD_COUNTER_KEY]!=nil;
BOOL hasLocalNumber = [UICKeyChainStore stringForKey:LOCAL_NUMBER_KEY]!=nil;
BOOL hasPassKey = [UICKeyChainStore stringForKey:SAVED_PASSWORD_KEY]!=nil;
BOOL hasSignaling = [UICKeyChainStore dataForKey:SIGNALING_MAC_KEY]!=nil;
@ -114,7 +112,7 @@
BOOL registered = [[NSUserDefaults.standardUserDefaults objectForKey:@"isRegistered"] boolValue];
return registered &&hasPassCounter && hasLocalNumber && hasPassKey && hasSignaling
return registered && hasLocalNumber && hasPassKey && hasSignaling
&& hasCipherKey && hasCipherKey && hasZIDKey && hasSignalingExtra;
}
@ -151,4 +149,27 @@
[UICKeyChainStore removeItemForKey:SIGNALING_EXTRA_KEY];
}
+ (void)clearUserDefaults{
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
[Environment.preferences setAndGetCurrentVersion];
[[NSUserDefaults standardUserDefaults] setObject:@YES forKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY];
[[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL)isMigratingTo2Dot0{
NSNumber *num = [[NSUserDefaults standardUserDefaults] objectForKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY];
if (!num) {
return NO;
} else {
return [num boolValue];
}
}
+ (void)clearMigrationFlag{
[[NSUserDefaults standardUserDefaults] setObject:nil forKey:IS_MIGRATING_FROM_1DOT0_TO_LARGER_KEY];
}
@end

@ -21,6 +21,7 @@
#import "TSContactThread.h"
#import "TSMessagesManager+sendMessages.h"
#import "UIImage+normalizeImage.h"
#import "VersionMigrations.h"
#import "PreferencesUtil.h"
#import "NSDate+millisecondTimeStamp.h"
@ -85,7 +86,7 @@ static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
[super viewWillAppear:animated];
[self checkIfEmptyView];
if (![TSAccountManager isRegistered] && ![Environment.preferences getIsMigratingToVersion2Dot0]){
if (![TSAccountManager isRegistered] && ![VersionMigrations isMigratingTo2Dot0]){
[self performSegueWithIdentifier:kShowSignupFlowSegue sender:self];
return;
}

Loading…
Cancel
Save