Add missing retains to promises.

This commit is contained in:
Matthew Chen 2018-12-11 09:39:29 -05:00
parent 222e07c5bd
commit 48bd0cfa06
7 changed files with 39 additions and 37 deletions

View File

@ -107,39 +107,40 @@ NS_ASSUME_NONNULL_BEGIN
canCancel:NO
backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) {
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringCode]);
[self.accountManager registerObjcWithVerificationCode:self.verificationCode pin:pinCode]
.then(^{
OWSAssertIsOnMainThread();
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringSubmittedCode]);
[[OWS2FAManager sharedManager] mark2FAAsEnabledWithPin:pinCode];
[[self.accountManager registerObjcWithVerificationCode:self.verificationCode pin:pinCode]
.then(^{
OWSAssertIsOnMainThread();
OWSProdInfo([OWSAnalyticsEvents registrationRegisteringSubmittedCode]);
[[OWS2FAManager sharedManager] mark2FAAsEnabledWithPin:pinCode];
OWSLogInfo(@"Successfully registered Signal account.");
dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{
OWSAssertIsOnMainThread();
OWSLogInfo(@"Successfully registered Signal account.");
dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{
OWSAssertIsOnMainThread();
[weakSelf verificationWasCompleted];
}];
});
})
.catch(^(NSError *error) {
OWSAssertIsOnMainThread();
OWSProdInfo([OWSAnalyticsEvents registrationRegistrationFailed]);
OWSLogError(@"error verifying challenge: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{
OWSAssertIsOnMainThread();
[weakSelf verificationWasCompleted];
}];
});
})
.catch(^(NSError *error) {
OWSAssertIsOnMainThread();
OWSProdInfo([OWSAnalyticsEvents registrationRegistrationFailed]);
OWSLogError(@"error verifying challenge: %@", error);
dispatch_async(dispatch_get_main_queue(), ^{
[modalActivityIndicator dismissWithCompletion:^{
OWSAssertIsOnMainThread();
[OWSAlerts showAlertWithTitle:NSLocalizedString(
@"REGISTER_2FA_REGISTRATION_FAILED_ALERT_TITLE",
@"Title for alert indicating that attempt to "
@"register with 'two-factor auth' failed.")
message:error.localizedDescription];
[OWSAlerts
showAlertWithTitle:NSLocalizedString(
@"REGISTER_2FA_REGISTRATION_FAILED_ALERT_TITLE",
@"Title for alert indicating that attempt to "
@"register with 'two-factor auth' failed.")
message:error.localizedDescription];
[weakSelf.entryView makePinTextFieldFirstResponder];
}];
});
});
[weakSelf.entryView makePinTextFieldFirstResponder];
}];
});
}) retainUntilComplete];
}];
}

View File

@ -187,7 +187,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
[OWSBackup.sharedManager setIsBackupEnabled:YES];
})
.thenInBackground(^{
[self.tsAccountManager updateAccountAttributes];
[[self.tsAccountManager updateAccountAttributes] retainUntilComplete];
[self succeed];
});

View File

@ -33,7 +33,7 @@ public class OWS111UDAttributesMigration: OWSDatabaseMigration {
}
private func doMigration() {
tsAccountManager.updateAccountAttributes()
tsAccountManager.updateAccountAttributes().retainUntilComplete()
self.dbReadWriteConnection().readWrite { transaction in
self.save(with: transaction)

View File

@ -860,7 +860,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
{
OWSUserProfile *userProfile = self.localUserProfile;
[userProfile clearWithProfileKey:[OWSAES256Key generateRandomKey] dbConnection:self.dbConnection completion:nil];
[self.tsAccountManager updateAccountAttributes];
[[self.tsAccountManager updateAccountAttributes] retainUntilComplete];
}
- (void)addUserToProfileWhitelist:(NSString *)recipientId

View File

@ -86,7 +86,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
}
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
[self updateAccountAttributesIfNecessary];
[[self updateAccountAttributesIfNecessary] retainUntilComplete];
}];
[[NSNotificationCenter defaultCenter] addObserver:self
@ -721,7 +721,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
OWSAssertIsOnMainThread();
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
[self updateAccountAttributesIfNecessary];
[[self updateAccountAttributesIfNecessary] retainUntilComplete];
}];
}

View File

@ -485,6 +485,6 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
dbConnection.setBool(value, forKey: kUDUnrestrictedAccessKey, inCollection: kUDCollection)
// Try to update the account attributes to reflect this change.
tsAccountManager.updateAccountAttributes()
tsAccountManager.updateAccountAttributes().retainUntilComplete()
}
}

View File

@ -10,6 +10,7 @@
#import "TSAccountManager.h"
#import "TSNetworkManager.h"
#import "YapDatabaseConnection+OWS.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
@ -89,7 +90,7 @@ const NSUInteger kDaySecs = kHourSecs * 24;
object:nil
userInfo:nil];
[self.tsAccountManager updateAccountAttributes];
[[self.tsAccountManager updateAccountAttributes] retainUntilComplete];
}
- (void)mark2FAAsEnabledWithPin:(NSString *)pin
@ -105,7 +106,7 @@ const NSUInteger kDaySecs = kHourSecs * 24;
object:nil
userInfo:nil];
[self.tsAccountManager updateAccountAttributes];
[[self.tsAccountManager updateAccountAttributes] retainUntilComplete];
}
- (void)requestEnable2FAWithPin:(NSString *)pin