diff --git a/Signal/src/Models/AccountManager.swift b/Signal/src/Models/AccountManager.swift index c0eefb8cb..dede8708f 100644 --- a/Signal/src/Models/AccountManager.swift +++ b/Signal/src/Models/AccountManager.swift @@ -114,14 +114,7 @@ public class AccountManager: NSObject { } func enableManualMessageFetching() -> Promise { - let (promise, fulfill, reject) = Promise.pending() - tsAccountManager.setIsManualMessageFetchEnabled(true) - .then(execute: { (_) in - fulfill(()) - }).catch(execute: { (error) in - reject(error) - }) - return promise + return tsAccountManager.setIsManualMessageFetchEnabled(true).asPromise().asVoid() } // MARK: Turn Server diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index 01efb6f34..3b94b2b26 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -625,17 +625,17 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); // No need to rotate the profile key. return success(); } - [self rotateProfileKeyWithSuccess:success - failure:failure - intersectingRecipientIds:intersectingRecipientIds - intersectingGroupIds:intersectingGroupIds]; + [self rotateProfileKeyWithIntersectingRecipientIds:intersectingRecipientIds + intersectingGroupIds:intersectingGroupIds + success:success + failure:failure]; }); } -- (void)rotateProfileKeyWithSuccess:(dispatch_block_t)success - failure:(ProfileManagerFailureBlock)failure - intersectingRecipientIds:(NSSet *)intersectingRecipientIds - intersectingGroupIds:(NSSet *)intersectingGroupIds { +- (void)rotateProfileKeyWithIntersectingRecipientIds:(NSSet *)intersectingRecipientIds + intersectingGroupIds:(NSSet *)intersectingGroupIds + success:(dispatch_block_t)success + failure:(ProfileManagerFailureBlock)failure { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // Rotate the profile key OWSLogInfo(@"Rotating the profile key."); diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 00857c0c7..3cb85c82e 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -632,6 +632,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa #pragma mark - Account Attributes - (AnyPromise *)updateAccountAttributes { + // Enqueue a "account attribute update", recording the "request time". [self.dbConnection setObject:[NSDate new] forKey:TSAccountManager_NeedsAccountAttributesUpdateKey inCollection:TSAccountManager_UserAccountCollection]; @@ -647,10 +648,11 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa return [AnyPromise promiseWithValue:@(1)]; } - AnyPromise *promise = [[SignalServiceRestClient new] updateAccountAttributes]; + AnyPromise *promise = [[SignalServiceRestClient new] updateAccountAttributesObjC]; promise = promise.then(^(id value) { [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - // Clear the update request unless a new update has been requested. + // Clear the update request unless a new update has been requested + // while this update was in flight. NSDate *_Nullable latestUpdateRequestDate = [transaction objectForKey:TSAccountManager_NeedsAccountAttributesUpdateKey inCollection:TSAccountManager_UserAccountCollection]; diff --git a/SignalServiceKit/src/Network/SignalServiceClient.swift b/SignalServiceKit/src/Network/SignalServiceClient.swift index 3d28d68bd..f1808cc26 100644 --- a/SignalServiceKit/src/Network/SignalServiceClient.swift +++ b/SignalServiceKit/src/Network/SignalServiceClient.swift @@ -10,7 +10,7 @@ public typealias RecipientIdentifier = String @objc public protocol SignalServiceClientObjC { - @objc func updateAccountAttributes() -> AnyPromise + @objc func updateAccountAttributesObjC() -> AnyPromise } public protocol SignalServiceClient: SignalServiceClientObjC { @@ -18,6 +18,7 @@ public protocol SignalServiceClient: SignalServiceClientObjC { func registerPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise func setCurrentSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise func requestUDSenderCertificate() -> Promise + func updateAccountAttributes() -> Promise func retrieveProfile(recipientId: RecipientIdentifier, unidentifiedAccess: SSKUnidentifiedAccess?) -> Promise } @@ -82,7 +83,11 @@ public class SignalServiceRestClient: NSObject, SignalServiceClient { } @objc - public func updateAccountAttributes() -> AnyPromise { + public func updateAccountAttributesObjC() -> AnyPromise { + return AnyPromise(updateAccountAttributes()) + } + + public func updateAccountAttributes() -> Promise { let request = OWSRequestFactory.updateAttributesRequest() let promise: Promise = networkManager.makePromise(request: request) .then(execute: { (_, _) in @@ -90,7 +95,7 @@ public class SignalServiceRestClient: NSObject, SignalServiceClient { }).catch(execute: { (error) in Logger.error("failed to update account attributes on server with error: \(error)") }) - return AnyPromise(promise) + return promise } public func retrieveProfile(recipientId: RecipientIdentifier, unidentifiedAccess: SSKUnidentifiedAccess?) -> Promise {