Convert backup logic to use promises.

This commit is contained in:
Matthew Chen 2018-11-27 11:49:30 -05:00
parent e19b457cb3
commit a9120906fa
5 changed files with 28 additions and 40 deletions

View File

@ -74,16 +74,16 @@ NS_ASSUME_NONNULL_BEGIN
__weak OWSBackupSettingsViewController *weakSelf = self;
[[self.backup checkCloudKitAccess]
.then(^{
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.iCloudError = nil;
[weakSelf updateTableContents];
});
OWSAssertIsOnMainThread();
weakSelf.iCloudError = nil;
[weakSelf updateTableContents];
})
.catch(^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.iCloudError = error;
[weakSelf updateTableContents];
});
OWSAssertIsOnMainThread();
weakSelf.iCloudError = error;
[weakSelf updateTableContents];
}) retainUntilComplete];
}

View File

@ -90,16 +90,14 @@ NS_ASSUME_NONNULL_BEGIN
NSString *recipientId = self.tsAccountManager.localNumber;
[[self.backup checkCloudKitAccess]
.then(^{
dispatch_async(dispatch_get_main_queue(), ^{
[OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId
fileUrl:[NSURL fileURLWithPath:filePath]
success:^(NSString *recordName) {
// Do nothing, the API method will log for us.
}
failure:^(NSError *error){
// Do nothing, the API method will log for us.
}];
});
[OWSBackupAPI saveTestFileToCloudWithRecipientId:recipientId
fileUrl:[NSURL fileURLWithPath:filePath]
success:^(NSString *recordName) {
// Do nothing, the API method will log for us.
}
failure:^(NSError *error){
// Do nothing, the API method will log for us.
}];
})
.catch(^(NSError *error){
// Do nothing, the API method will log for us.

View File

@ -474,7 +474,7 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
}
[[OWSBackupAPI checkCloudKitAccessObjc]
.then(^{
.thenInBackground(^{
[OWSBackupAPI checkForManifestInCloudWithRecipientId:recipientId
success:^(BOOL value) {
dispatch_async(dispatch_get_main_queue(), ^{
@ -488,9 +488,7 @@ NSArray<NSString *> *MiscCollectionsToBackup(void)
}];
})
.catch(^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
failure(error);
});
failure(error);
}) retainUntilComplete];
}

View File

@ -349,17 +349,13 @@ NS_ASSUME_NONNULL_BEGIN
__weak OWSBackupExportJob *weakSelf = self;
[[self.backup checkCloudKitAccess]
.then(^{
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf start];
});
.thenInBackground(^{
[weakSelf start];
})
.catch(^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf failWithErrorDescription:
NSLocalizedString(@"BACKUP_EXPORT_ERROR_COULD_NOT_EXPORT",
@"Error indicating the backup export could not export the user's data.")];
});
[weakSelf failWithErrorDescription:
NSLocalizedString(@"BACKUP_EXPORT_ERROR_COULD_NOT_EXPORT",
@"Error indicating the backup export could not export the user's data.")];
}) retainUntilComplete];
}

View File

@ -78,17 +78,13 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
__weak OWSBackupImportJob *weakSelf = self;
[[self.backup checkCloudKitAccess]
.then(^{
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf start];
});
.thenInBackground(^{
[weakSelf start];
})
.catch(^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf failWithErrorDescription:
NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT",
@"Error indicating the backup import could not import the user's data.")];
});
[weakSelf failWithErrorDescription:
NSLocalizedString(@"BACKUP_IMPORT_ERROR_COULD_NOT_IMPORT",
@"Error indicating the backup import could not import the user's data.")];
}) retainUntilComplete];
}