Asyncify updateAccountAttributes
This commit is contained in:
parent
40924ecbbb
commit
95a1cd89bc
@ -292,37 +292,34 @@ extension RegistrationCoordinatorImpl {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns nil error if success.
|
||||
public static func makeUpdateAccountAttributesRequest(
|
||||
_ attributes: AccountAttributes,
|
||||
auth: ChatServiceAuth,
|
||||
signalService: OWSSignalServiceProtocol,
|
||||
retriesLeft: Int = RegistrationCoordinatorImpl.Constants.networkErrorRetries
|
||||
) -> Guarantee<Error?> {
|
||||
) async throws {
|
||||
let request = RegistrationRequestFactory.updatePrimaryDeviceAccountAttributesRequest(
|
||||
attributes,
|
||||
auth: auth
|
||||
)
|
||||
return signalService.urlSessionForMainSignalService().promiseForTSRequest(request)
|
||||
.map(on: SyncScheduler()) { response in
|
||||
guard response.responseStatusCode >= 200, response.responseStatusCode < 300 else {
|
||||
// Errors are undifferentiated; the only actual error we can get is an unauthenticated
|
||||
// one and there isn't any way to handle that as different from a, say server 500.
|
||||
return OWSAssertionError("Got unexpected response code from update attributes request: \(response.responseStatusCode).")
|
||||
}
|
||||
return nil
|
||||
do {
|
||||
let response = try await signalService.urlSessionForMainSignalService().performRequest(request)
|
||||
guard response.responseStatusCode >= 200, response.responseStatusCode < 300 else {
|
||||
// Errors are undifferentiated; the only actual error we can get is an unauthenticated
|
||||
// one and there isn't any way to handle that as different from a, say server 500.
|
||||
throw OWSAssertionError("Got unexpected response code from update attributes request: \(response.responseStatusCode).")
|
||||
}
|
||||
.recover(on: SyncScheduler()) { error in
|
||||
if error.isNetworkFailureOrTimeout, retriesLeft > 0 {
|
||||
return makeUpdateAccountAttributesRequest(
|
||||
attributes,
|
||||
auth: auth,
|
||||
signalService: signalService,
|
||||
retriesLeft: retriesLeft - 1
|
||||
)
|
||||
}
|
||||
return .value(error)
|
||||
} catch {
|
||||
if error.isNetworkFailureOrTimeout, retriesLeft > 0 {
|
||||
return try await makeUpdateAccountAttributesRequest(
|
||||
attributes,
|
||||
auth: auth,
|
||||
signalService: signalService,
|
||||
retriesLeft: retriesLeft - 1
|
||||
)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
enum WhoAmIResponse {
|
||||
|
||||
@ -1443,7 +1443,7 @@ public class RegistrationCoordinatorImpl: RegistrationCoordinator {
|
||||
) -> Guarantee<RegistrationStep> {
|
||||
Logger.info("")
|
||||
|
||||
return updateAccountAttributes(accountIdentity)
|
||||
return Guarantee.wrapAsync { await self.updateAccountAttributes(accountIdentity) }
|
||||
.then(on: DispatchQueue.main) { [weak self] error -> Guarantee<RegistrationStep> in
|
||||
guard let self else {
|
||||
return unretainedSelfError()
|
||||
@ -3886,10 +3886,10 @@ public class RegistrationCoordinatorImpl: RegistrationCoordinator {
|
||||
inMemoryState.udAccessKey = udAccessKey
|
||||
}
|
||||
|
||||
private func updateAccountAttributes(_ accountIdentity: AccountIdentity) -> Guarantee<Error?> {
|
||||
private func updateAccountAttributes(_ accountIdentity: AccountIdentity) async -> Error? {
|
||||
Logger.info("")
|
||||
return Service
|
||||
.makeUpdateAccountAttributesRequest(
|
||||
do {
|
||||
try await Service.makeUpdateAccountAttributesRequest(
|
||||
makeAccountAttributes(
|
||||
isManualMessageFetchEnabled: inMemoryState.isManualMessageFetchEnabled,
|
||||
twoFAMode: self.attributes2FAMode(e164: accountIdentity.e164)
|
||||
@ -3897,6 +3897,10 @@ public class RegistrationCoordinatorImpl: RegistrationCoordinator {
|
||||
auth: accountIdentity.chatServiceAuth,
|
||||
signalService: deps.signalService,
|
||||
)
|
||||
return nil
|
||||
} catch {
|
||||
return error
|
||||
}
|
||||
}
|
||||
|
||||
private func updatePhoneNumberDiscoverability(accountIdentity: AccountIdentity, phoneNumberDiscoverability: PhoneNumberDiscoverability) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user