Implement backup import logic.
This commit is contained in:
parent
04c527a0f4
commit
5035cb040e
|
@ -61,6 +61,7 @@ typedef NS_ENUM(NSUInteger, OWSBackupState) {
|
|||
// preserve our PIN and/or private key so that restored users
|
||||
// continues to backup.
|
||||
- (void)tryToImportBackup;
|
||||
- (void)cancelImportBackup;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -320,6 +320,18 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
self.backupImport =
|
||||
[[OWSBackupImport alloc] initWithDelegate:self primaryStorage:[OWSPrimaryStorage sharedManager]];
|
||||
[self.backupImport startAsync];
|
||||
|
||||
[self postDidChangeNotification];
|
||||
}
|
||||
|
||||
- (void)cancelImportBackup
|
||||
{
|
||||
[self.backupImport cancel];
|
||||
self.backupImport = nil;
|
||||
|
||||
_backupImportState = OWSBackupState_Idle;
|
||||
|
||||
[self postDidChangeNotification];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
@ -392,13 +404,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
DDLogInfo(@"%@ %s: %@, %@", self.logTag, __PRETTY_FUNCTION__, description, progress);
|
||||
|
||||
BOOL didChange = !([NSObject isNullableObject:self.backupExportDescription equalTo:description] &&
|
||||
[NSObject isNullableObject:self.backupExportProgress equalTo:progress]);
|
||||
|
||||
self.backupExportDescription = description;
|
||||
self.backupExportProgress = progress;
|
||||
|
||||
[self postDidChangeNotification];
|
||||
if (didChange) {
|
||||
[self postDidChangeNotification];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - OWSBackupImportDelegate
|
||||
|
||||
- (void)backupImportDidSucceed:(OWSBackupImport *)backupImport
|
||||
|
@ -447,16 +463,23 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
DDLogInfo(@"%@ %s: %@, %@", self.logTag, __PRETTY_FUNCTION__, description, progress);
|
||||
|
||||
BOOL didChange = !([NSObject isNullableObject:self.backupImportDescription equalTo:description] &&
|
||||
[NSObject isNullableObject:self.backupImportProgress equalTo:progress]);
|
||||
|
||||
self.backupImportDescription = description;
|
||||
self.backupImportProgress = progress;
|
||||
|
||||
[self postDidChangeNotification];
|
||||
if (didChange) {
|
||||
[self postDidChangeNotification];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Notifications
|
||||
|
||||
- (void)postDidChangeNotification
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:NSNotificationNameBackupStateDidChange
|
||||
object:nil
|
||||
userInfo:nil];
|
||||
|
|
|
@ -106,17 +106,11 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|||
{
|
||||
@synchronized(self)
|
||||
{
|
||||
BOOL isEqual;
|
||||
if (avatarUrlPath != nil) {
|
||||
isEqual = [avatarUrlPath isEqual:_avatarUrlPath];
|
||||
} else {
|
||||
// are they both nil?
|
||||
isEqual = _avatarUrlPath == nil;
|
||||
}
|
||||
BOOL didChange = ![NSObject isNullableObject:_avatarUrlPath equalTo:avatarUrlPath];
|
||||
|
||||
_avatarUrlPath = avatarUrlPath;
|
||||
|
||||
if (!isEqual) {
|
||||
if (didChange) {
|
||||
// If the avatarURL changed, the avatarFileName can't be valid.
|
||||
// Clear it.
|
||||
self.avatarFileName = nil;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (NSString *)logTag;
|
||||
|
||||
+ (BOOL)isNullableObject:(nullable NSObject *)left equalTo:(nullable NSObject *)right;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSObject+OWS.h"
|
||||
|
@ -21,6 +21,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return self.class.logTag;
|
||||
}
|
||||
|
||||
+ (BOOL)isNullableObject:(nullable NSObject *)left equalTo:(nullable NSObject *)right
|
||||
{
|
||||
if (!left && !right) {
|
||||
return YES;
|
||||
} else if (!left || !right) {
|
||||
return NO;
|
||||
} else {
|
||||
return [left isEqual:right];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -35,6 +35,10 @@ typedef NS_ENUM(NSInteger, OWSErrorCode) {
|
|||
OWSErrorCodeExportBackupFailed = 777415,
|
||||
// A possibly recoverable error occured while exporting a backup.
|
||||
OWSErrorCodeExportBackupError = 777416,
|
||||
// A non-recoverable error occured while importing a backup.
|
||||
OWSErrorCodeImportBackupFailed = 777417,
|
||||
// A possibly recoverable error occured while importing a backup.
|
||||
OWSErrorCodeImportBackupError = 777418,
|
||||
};
|
||||
|
||||
extern NSString *const OWSErrorRecipientIdentifierKey;
|
||||
|
|
Loading…
Reference in New Issue