diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberRepository.kt index a62ffccf3e..746fc7cd08 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberRepository.kt @@ -23,7 +23,7 @@ import org.thoughtcrime.securesms.pin.KbsRepository import org.thoughtcrime.securesms.pin.KeyBackupSystemWrongPinException import org.thoughtcrime.securesms.pin.TokenData import org.thoughtcrime.securesms.recipients.Recipient -import org.thoughtcrime.securesms.registration.VerifyAccountRepository +import org.thoughtcrime.securesms.registration.VerifyResponse import org.thoughtcrime.securesms.storage.StorageSyncHelper import org.whispersystems.signalservice.api.KbsPinData import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException @@ -94,7 +94,7 @@ class ChangeNumberRepository( .timeout(15, TimeUnit.SECONDS) } - fun changeNumber(code: String, newE164: String, pniUpdateMode: Boolean = false): Single> { + fun changeNumber(code: String, newE164: String, pniUpdateMode: Boolean = false): Single> { return Single.fromCallable { var completed = false var attempts = 0 @@ -121,7 +121,7 @@ class ChangeNumberRepository( } } - changeNumberResponse + VerifyResponse.from(changeNumberResponse, null, null) }.subscribeOn(Schedulers.single()) .onErrorReturn { t -> ServiceResponse.forExecutionError(t) } } @@ -131,7 +131,7 @@ class ChangeNumberRepository( newE164: String, pin: String, tokenData: TokenData - ): Single> { + ): Single> { return Single.fromCallable { val kbsData: KbsPinData val registrationLock: String @@ -172,7 +172,7 @@ class ChangeNumberRepository( } } - VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse.from(changeNumberResponse, kbsData) + VerifyResponse.from(changeNumberResponse, kbsData, pin) }.subscribeOn(Schedulers.single()) .onErrorReturn { t -> ServiceResponse.forExecutionError(t) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberViewModel.kt index 0a0237fb31..931e7dc06f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/changenumber/ChangeNumberViewModel.kt @@ -18,16 +18,15 @@ import org.thoughtcrime.securesms.pin.KbsRepository import org.thoughtcrime.securesms.pin.TokenData import org.thoughtcrime.securesms.registration.SmsRetrieverReceiver import org.thoughtcrime.securesms.registration.VerifyAccountRepository -import org.thoughtcrime.securesms.registration.VerifyAccountResponseProcessor -import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithoutKbs -import org.thoughtcrime.securesms.registration.VerifyCodeWithRegistrationLockResponseProcessor -import org.thoughtcrime.securesms.registration.VerifyProcessor +import org.thoughtcrime.securesms.registration.VerifyResponse +import org.thoughtcrime.securesms.registration.VerifyResponseProcessor +import org.thoughtcrime.securesms.registration.VerifyResponseWithRegistrationLockProcessor +import org.thoughtcrime.securesms.registration.VerifyResponseWithoutKbs import org.thoughtcrime.securesms.registration.viewmodel.BaseRegistrationViewModel import org.thoughtcrime.securesms.registration.viewmodel.NumberViewState import org.thoughtcrime.securesms.util.DefaultValueLiveData import org.whispersystems.signalservice.api.push.PNI import org.whispersystems.signalservice.internal.ServiceResponse -import org.whispersystems.signalservice.internal.push.VerifyAccountResponse import java.util.Objects private val TAG: String = Log.tag(ChangeNumberViewModel::class.java) @@ -121,19 +120,19 @@ class ChangeNumberViewModel( return changeNumberRepository.ensureDecryptionsDrained() } - override fun verifyCodeWithoutRegistrationLock(code: String): Single { + override fun verifyCodeWithoutRegistrationLock(code: String): Single { return super.verifyCodeWithoutRegistrationLock(code) .compose(ChangeNumberRepository::acquireReleaseChangeNumberLock) .flatMap(this::attemptToUnlockChangeNumber) } - override fun verifyCodeAndRegisterAccountWithRegistrationLock(pin: String): Single { + override fun verifyCodeAndRegisterAccountWithRegistrationLock(pin: String): Single { return super.verifyCodeAndRegisterAccountWithRegistrationLock(pin) .compose(ChangeNumberRepository::acquireReleaseChangeNumberLock) .flatMap(this::attemptToUnlockChangeNumber) } - private fun attemptToUnlockChangeNumber(processor: T): Single { + private fun attemptToUnlockChangeNumber(processor: T): Single { return if (processor.hasResult() || processor.isServerSentError()) { SignalStore.misc().unlockChangeNumber() SignalStore.misc().clearPendingChangeNumberMetadata() @@ -152,30 +151,30 @@ class ChangeNumberViewModel( } } - override fun verifyAccountWithoutRegistrationLock(): Single> { + override fun verifyAccountWithoutRegistrationLock(): Single> { return changeNumberRepository.changeNumber(textCodeEntered, number.e164Number) } - override fun verifyAccountWithRegistrationLock(pin: String, kbsTokenData: TokenData): Single> { + override fun verifyAccountWithRegistrationLock(pin: String, kbsTokenData: TokenData): Single> { return changeNumberRepository.changeNumber(textCodeEntered, number.e164Number, pin, kbsTokenData) } @WorkerThread - override fun onVerifySuccess(processor: VerifyAccountResponseProcessor): Single { - return changeNumberRepository.changeLocalNumber(number.e164Number, PNI.parseOrThrow(processor.result.pni)) - .map { processor } - .onErrorReturn { t -> - Log.w(TAG, "Error attempting to change local number", t) - VerifyAccountResponseWithoutKbs(ServiceResponse.forUnknownError(t)) - } - } - - override fun onVerifySuccessWithRegistrationLock(processor: VerifyCodeWithRegistrationLockResponseProcessor, pin: String): Single { + override fun onVerifySuccess(processor: VerifyResponseProcessor): Single { return changeNumberRepository.changeLocalNumber(number.e164Number, PNI.parseOrThrow(processor.result.verifyAccountResponse.pni)) .map { processor } .onErrorReturn { t -> Log.w(TAG, "Error attempting to change local number", t) - VerifyCodeWithRegistrationLockResponseProcessor(ServiceResponse.forUnknownError(t), processor.token) + VerifyResponseWithoutKbs(ServiceResponse.forUnknownError(t)) + } + } + + override fun onVerifySuccessWithRegistrationLock(processor: VerifyResponseWithRegistrationLockProcessor, pin: String): Single { + return changeNumberRepository.changeLocalNumber(number.e164Number, PNI.parseOrThrow(processor.result.verifyAccountResponse.pni)) + .map { processor } + .onErrorReturn { t -> + Log.w(TAG, "Error attempting to change local number", t) + VerifyResponseWithRegistrationLockProcessor(ServiceResponse.forUnknownError(t), processor.tokenData) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PnpInitializeDevicesJob.kt b/app/src/main/java/org/thoughtcrime/securesms/jobs/PnpInitializeDevicesJob.kt index f0f156c14f..bdfae33392 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PnpInitializeDevicesJob.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PnpInitializeDevicesJob.kt @@ -9,7 +9,7 @@ import org.thoughtcrime.securesms.jobmanager.Job import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint import org.thoughtcrime.securesms.keyvalue.SignalStore import org.thoughtcrime.securesms.recipients.Recipient -import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithoutKbs +import org.thoughtcrime.securesms.registration.VerifyResponseWithoutKbs import org.thoughtcrime.securesms.util.FeatureFlags import org.thoughtcrime.securesms.util.TextSecurePreferences import java.io.IOException @@ -89,7 +89,7 @@ class PnpInitializeDevicesJob private constructor(parameters: Parameters) : Base Log.i(TAG, "Calling change number with our current number to distribute PNI messages") changeNumberRepository .changeNumber(code = PLACEHOLDER_CODE, newE164 = e164, pniUpdateMode = true) - .map(::VerifyAccountResponseWithoutKbs) + .map(::VerifyResponseWithoutKbs) .safeBlockingGet() .resultOrThrow } catch (e: InterruptedException) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/RegistrationRepository.java b/app/src/main/java/org/thoughtcrime/securesms/registration/RegistrationRepository.java index beff7dca23..7b7891fa07 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/RegistrationRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/RegistrationRepository.java @@ -29,7 +29,6 @@ import org.thoughtcrime.securesms.pin.PinState; import org.thoughtcrime.securesms.push.AccountManagerFactory; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientId; -import org.thoughtcrime.securesms.registration.VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse; import org.thoughtcrime.securesms.service.DirectoryRefreshListener; import org.thoughtcrime.securesms.service.RotateSignedPreKeyListener; import org.thoughtcrime.securesms.util.TextSecurePreferences; @@ -93,27 +92,12 @@ public final class RegistrationRepository { return profileKey; } - public Single> registerAccountWithoutRegistrationLock(@NonNull RegistrationData registrationData, - @NonNull VerifyAccountResponse response) + public Single> registerAccount(@NonNull RegistrationData registrationData, + @NonNull VerifyResponse response) { - return registerAccount(registrationData, response, null, null); - } - - public Single> registerAccountWithRegistrationLock(@NonNull RegistrationData registrationData, - @NonNull VerifyAccountWithRegistrationLockResponse response, - @NonNull String pin) - { - return registerAccount(registrationData, response.getVerifyAccountResponse(), pin, response.getKbsData()); - } - - private Single> registerAccount(@NonNull RegistrationData registrationData, - @NonNull VerifyAccountResponse response, - @Nullable String pin, - @Nullable KbsPinData kbsData) - { - return Single.>fromCallable(() -> { + return Single.>fromCallable(() -> { try { - registerAccountInternal(registrationData, response, pin, kbsData); + registerAccountInternal(registrationData, response.getVerifyAccountResponse(), response.getPin(), response.getKbsData()); JobManager jobManager = ApplicationDependencies.getJobManager(); jobManager.add(new DirectoryRefreshJob(false)); diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountRepository.kt index 5933e01991..4399afb0e1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountRepository.kt @@ -51,7 +51,7 @@ class VerifyAccountRepository(private val context: Application) { }.subscribeOn(Schedulers.io()) } - fun verifyAccount(registrationData: RegistrationData): Single> { + fun verifyAccount(registrationData: RegistrationData): Single> { val universalUnidentifiedAccess: Boolean = TextSecurePreferences.isUniversalUnidentifiedAccess(context) val unidentifiedAccessKey: ByteArray = UnidentifiedAccess.deriveAccessKeyFrom(registrationData.profileKey) @@ -63,7 +63,7 @@ class VerifyAccountRepository(private val context: Application) { ) return Single.fromCallable { - accountManager.verifyAccount( + val response = accountManager.verifyAccount( registrationData.code, registrationData.registrationId, registrationData.isNotFcm, @@ -73,10 +73,11 @@ class VerifyAccountRepository(private val context: Application) { SignalStore.phoneNumberPrivacy().phoneNumberListingMode.isDiscoverable, registrationData.pniRegistrationId ) + VerifyResponse.from(response, null, null) }.subscribeOn(Schedulers.io()) } - fun verifyAccountWithPin(registrationData: RegistrationData, pin: String, tokenData: TokenData): Single> { + fun verifyAccountWithPin(registrationData: RegistrationData, pin: String, tokenData: TokenData): Single> { val universalUnidentifiedAccess: Boolean = TextSecurePreferences.isUniversalUnidentifiedAccess(context) val unidentifiedAccessKey: ByteArray = UnidentifiedAccess.deriveAccessKeyFrom(registrationData.profileKey) @@ -103,7 +104,7 @@ class VerifyAccountRepository(private val context: Application) { SignalStore.phoneNumberPrivacy().phoneNumberListingMode.isDiscoverable, registrationData.pniRegistrationId ) - VerifyAccountWithRegistrationLockResponse.from(response, kbsData) + VerifyResponse.from(response, kbsData, pin) } catch (e: KeyBackupSystemWrongPinException) { ServiceResponse.forExecutionError(e) } catch (e: KeyBackupSystemNoDataException) { @@ -125,15 +126,4 @@ class VerifyAccountRepository(private val context: Application) { private val PUSH_REQUEST_TIMEOUT = TimeUnit.SECONDS.toMillis(5) } - data class VerifyAccountWithRegistrationLockResponse(val verifyAccountResponse: VerifyAccountResponse, val kbsData: KbsPinData) { - companion object { - fun from(response: ServiceResponse, kbsData: KbsPinData): ServiceResponse { - return if (response.result.isPresent) { - ServiceResponse.forResult(VerifyAccountWithRegistrationLockResponse(response.result.get(), kbsData), 200, null) - } else { - ServiceResponse.coerceError(response) - } - } - } - } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyCodeWithRegistrationLockResponseProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyCodeWithRegistrationLockResponseProcessor.kt deleted file mode 100644 index 2a1d064fc8..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyCodeWithRegistrationLockResponseProcessor.kt +++ /dev/null @@ -1,59 +0,0 @@ -package org.thoughtcrime.securesms.registration - -import org.thoughtcrime.securesms.pin.KeyBackupSystemWrongPinException -import org.thoughtcrime.securesms.pin.TokenData -import org.thoughtcrime.securesms.registration.VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse -import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException -import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException -import org.whispersystems.signalservice.internal.ServiceResponse -import org.whispersystems.signalservice.internal.ServiceResponseProcessor -import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse -import org.whispersystems.signalservice.internal.push.VerifyAccountResponse - -/** - * Process responses from attempting to verify an account with registration lock for use in - * account registration. - */ -class VerifyCodeWithRegistrationLockResponseProcessor( - response: ServiceResponse, - val token: TokenData -) : ServiceResponseProcessor(response), VerifyProcessor { - - public override fun rateLimit(): Boolean { - return super.rateLimit() - } - - public override fun getError(): Throwable? { - return super.getError() - } - - public override fun registrationLock(): Boolean { - return super.registrationLock() - } - - fun wrongPin(): Boolean { - return error is KeyBackupSystemWrongPinException - } - - fun getTokenResponse(): TokenResponse { - return (error as KeyBackupSystemWrongPinException).tokenResponse - } - - fun isKbsLocked(): Boolean { - return error is KeyBackupSystemNoDataException - } - - fun updatedIfRegistrationFailed(response: ServiceResponse): VerifyCodeWithRegistrationLockResponseProcessor { - if (response.result.isPresent) { - return this - } - - return VerifyCodeWithRegistrationLockResponseProcessor(ServiceResponse.coerceError(response), token) - } - - override fun isServerSentError(): Boolean { - return error is NonSuccessfulResponseCodeException || - error is KeyBackupSystemWrongPinException || - error is KeyBackupSystemNoDataException - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyProcessor.kt deleted file mode 100644 index ce09ec01cb..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyProcessor.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.thoughtcrime.securesms.registration - -interface VerifyProcessor { - fun hasResult(): Boolean - fun isServerSentError(): Boolean -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyResponse.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyResponse.kt new file mode 100644 index 0000000000..a84f00b5c5 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyResponse.kt @@ -0,0 +1,17 @@ +package org.thoughtcrime.securesms.registration + +import org.whispersystems.signalservice.api.KbsPinData +import org.whispersystems.signalservice.internal.ServiceResponse +import org.whispersystems.signalservice.internal.push.VerifyAccountResponse + +data class VerifyResponse(val verifyAccountResponse: VerifyAccountResponse, val kbsData: KbsPinData?, val pin: String?) { + companion object { + fun from(response: ServiceResponse, kbsData: KbsPinData?, pin: String?): ServiceResponse { + return if (response.result.isPresent) { + ServiceResponse.forResult(VerifyResponse(response.result.get(), kbsData, pin), 200, null) + } else { + ServiceResponse.coerceError(response) + } + } + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountResponseProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyResponseProcessor.kt similarity index 50% rename from app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountResponseProcessor.kt rename to app/src/main/java/org/thoughtcrime/securesms/registration/VerifyResponseProcessor.kt index 0cb9e669c0..057dc94ddd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyAccountResponseProcessor.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/VerifyResponseProcessor.kt @@ -1,18 +1,18 @@ package org.thoughtcrime.securesms.registration +import org.thoughtcrime.securesms.pin.KeyBackupSystemWrongPinException import org.thoughtcrime.securesms.pin.TokenData +import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException import org.whispersystems.signalservice.internal.ServiceResponse import org.whispersystems.signalservice.internal.ServiceResponseProcessor +import org.whispersystems.signalservice.internal.contacts.entities.TokenResponse import org.whispersystems.signalservice.internal.push.LockedException -import org.whispersystems.signalservice.internal.push.VerifyAccountResponse /** * Process responses from attempting to verify an account for use in account registration. */ -sealed class VerifyAccountResponseProcessor( - response: ServiceResponse -) : ServiceResponseProcessor(response), VerifyProcessor { +sealed class VerifyResponseProcessor(response: ServiceResponse) : ServiceResponseProcessor(response) { open val tokenData: TokenData? = null @@ -36,7 +36,7 @@ sealed class VerifyAccountResponseProcessor( return error as LockedException } - override fun isServerSentError(): Boolean { + open fun isServerSentError(): Boolean { return error is NonSuccessfulResponseCodeException } @@ -46,7 +46,7 @@ sealed class VerifyAccountResponseProcessor( /** * Verify processor specific to verifying without needing to handle registration lock. */ -class VerifyAccountResponseWithoutKbs(response: ServiceResponse) : VerifyAccountResponseProcessor(response) { +class VerifyResponseWithoutKbs(response: ServiceResponse) : VerifyResponseProcessor(response) { override fun isKbsLocked(): Boolean { return registrationLock() && getLockedException().basicStorageCredentials == null } @@ -56,11 +56,7 @@ class VerifyAccountResponseWithoutKbs(response: ServiceResponse, - override val tokenData: TokenData -) : VerifyAccountResponseProcessor(response) { - +class VerifyResponseWithSuccessfulKbs(response: ServiceResponse, override val tokenData: TokenData) : VerifyResponseProcessor(response) { override fun isKbsLocked(): Boolean { return registrationLock() && tokenData.triesRemaining == 0 } @@ -70,8 +66,41 @@ class VerifyAccountResponseWithSuccessfulKbs( * Verify processor specific to verifying and unsuccessfully retrieving KBS information that * is required for attempting to verify a registration locked account. */ -class VerifyAccountResponseWithFailedKbs(response: ServiceResponse) : VerifyAccountResponseProcessor(ServiceResponse.coerceError(response)) { +class VerifyResponseWithFailedKbs(response: ServiceResponse) : VerifyResponseProcessor(ServiceResponse.coerceError(response)) { override fun isKbsLocked(): Boolean { return false } } + +/** + * Process responses from attempting to verify an account with registration lock for use in + * account registration. + */ +class VerifyResponseWithRegistrationLockProcessor(response: ServiceResponse, override val tokenData: TokenData?) : VerifyResponseProcessor(response) { + + fun wrongPin(): Boolean { + return error is KeyBackupSystemWrongPinException + } + + fun getTokenResponse(): TokenResponse { + return (error as KeyBackupSystemWrongPinException).tokenResponse + } + + override fun isKbsLocked(): Boolean { + return error is KeyBackupSystemNoDataException + } + + fun updatedIfRegistrationFailed(response: ServiceResponse): VerifyResponseWithRegistrationLockProcessor { + if (response.result.isPresent) { + return this + } + + return VerifyResponseWithRegistrationLockProcessor(ServiceResponse.coerceError(response), tokenData) + } + + override fun isServerSentError(): Boolean { + return super.isServerSentError() || + error is KeyBackupSystemWrongPinException || + error is KeyBackupSystemNoDataException + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/fragments/BaseRegistrationLockFragment.java b/app/src/main/java/org/thoughtcrime/securesms/registration/fragments/BaseRegistrationLockFragment.java index efa2301481..3c4bf3f391 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/fragments/BaseRegistrationLockFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/fragments/BaseRegistrationLockFragment.java @@ -177,7 +177,7 @@ public abstract class BaseRegistrationLockFragment extends LoggingFragment { if (processor.hasResult()) { handleSuccessfulPinEntry(pin); } else if (processor.wrongPin()) { - onIncorrectKbsRegistrationLockPin(processor.getToken()); + onIncorrectKbsRegistrationLockPin(processor.getTokenData()); } else if (processor.isKbsLocked() || processor.registrationLock()) { onKbsAccountLocked(); } else if (processor.rateLimit()) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/BaseRegistrationViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/BaseRegistrationViewModel.java index 461d915df5..08a18ffa12 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/BaseRegistrationViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/BaseRegistrationViewModel.java @@ -11,14 +11,13 @@ import org.thoughtcrime.securesms.pin.TokenData; import org.thoughtcrime.securesms.registration.RequestVerificationCodeResponseProcessor; import org.thoughtcrime.securesms.registration.VerifyAccountRepository; import org.thoughtcrime.securesms.registration.VerifyAccountRepository.Mode; -import org.thoughtcrime.securesms.registration.VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse; -import org.thoughtcrime.securesms.registration.VerifyAccountResponseProcessor; -import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithFailedKbs; -import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithSuccessfulKbs; -import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithoutKbs; -import org.thoughtcrime.securesms.registration.VerifyCodeWithRegistrationLockResponseProcessor; +import org.thoughtcrime.securesms.registration.VerifyResponse; +import org.thoughtcrime.securesms.registration.VerifyResponseProcessor; +import org.thoughtcrime.securesms.registration.VerifyResponseWithFailedKbs; +import org.thoughtcrime.securesms.registration.VerifyResponseWithSuccessfulKbs; +import org.thoughtcrime.securesms.registration.VerifyResponseWithoutKbs; +import org.thoughtcrime.securesms.registration.VerifyResponseWithRegistrationLockProcessor; import org.whispersystems.signalservice.internal.ServiceResponse; -import org.whispersystems.signalservice.internal.push.VerifyAccountResponse; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -202,18 +201,18 @@ public abstract class BaseRegistrationViewModel extends ViewModel { }); } - public Single verifyCodeWithoutRegistrationLock(@NonNull String code) { + public Single verifyCodeWithoutRegistrationLock(@NonNull String code) { onVerificationCodeEntered(code); return verifyAccountWithoutRegistrationLock() - .map(VerifyAccountResponseWithoutKbs::new) + .map(VerifyResponseWithoutKbs::new) .flatMap(processor -> { if (processor.hasResult()) { return onVerifySuccess(processor); } else if (processor.registrationLock() && !processor.isKbsLocked()) { return kbsRepository.getToken(processor.getLockedException().getBasicStorageCredentials()) - .map(r -> r.getResult().isPresent() ? new VerifyAccountResponseWithSuccessfulKbs(processor.getResponse(), r.getResult().get()) - : new VerifyAccountResponseWithFailedKbs(r)); + .map(r -> r.getResult().isPresent() ? new VerifyResponseWithSuccessfulKbs(processor.getResponse(), r.getResult().get()) + : new VerifyResponseWithFailedKbs(r)); } return Single.just(processor); }) @@ -228,33 +227,33 @@ public abstract class BaseRegistrationViewModel extends ViewModel { }); } - public Single verifyCodeAndRegisterAccountWithRegistrationLock(@NonNull String pin) { + public Single verifyCodeAndRegisterAccountWithRegistrationLock(@NonNull String pin) { TokenData kbsTokenData = Objects.requireNonNull(getKeyBackupCurrentToken()); return verifyAccountWithRegistrationLock(pin, kbsTokenData) - .map(r -> new VerifyCodeWithRegistrationLockResponseProcessor(r, kbsTokenData)) + .map(r -> new VerifyResponseWithRegistrationLockProcessor(r, kbsTokenData)) .flatMap(processor -> { if (processor.hasResult()) { return onVerifySuccessWithRegistrationLock(processor, pin); } else if (processor.wrongPin()) { TokenData newToken = TokenData.withResponse(kbsTokenData, processor.getTokenResponse()); - return Single.just(new VerifyCodeWithRegistrationLockResponseProcessor(processor.getResponse(), newToken)); + return Single.just(new VerifyResponseWithRegistrationLockProcessor(processor.getResponse(), newToken)); } return Single.just(processor); }) .observeOn(AndroidSchedulers.mainThread()) .doOnSuccess(processor -> { if (processor.wrongPin()) { - setKeyBackupTokenData(processor.getToken()); + setKeyBackupTokenData(processor.getTokenData()); } }); } - protected abstract Single> verifyAccountWithoutRegistrationLock(); + protected abstract Single> verifyAccountWithoutRegistrationLock(); - protected abstract Single> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData); + protected abstract Single> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData); - protected abstract Single onVerifySuccess(@NonNull VerifyAccountResponseProcessor processor); + protected abstract Single onVerifySuccess(@NonNull VerifyResponseProcessor processor); - protected abstract Single onVerifySuccessWithRegistrationLock(@NonNull VerifyCodeWithRegistrationLockResponseProcessor processor, String pin); + protected abstract Single onVerifySuccessWithRegistrationLock(@NonNull VerifyResponseWithRegistrationLockProcessor processor, String pin); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/RegistrationViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/RegistrationViewModel.java index 9131d5f546..9c57eb136f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/RegistrationViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/registration/viewmodel/RegistrationViewModel.java @@ -15,12 +15,12 @@ import org.thoughtcrime.securesms.registration.RegistrationData; import org.thoughtcrime.securesms.registration.RegistrationRepository; import org.thoughtcrime.securesms.registration.RequestVerificationCodeResponseProcessor; import org.thoughtcrime.securesms.registration.VerifyAccountRepository; -import org.thoughtcrime.securesms.registration.VerifyAccountResponseProcessor; -import org.thoughtcrime.securesms.registration.VerifyAccountResponseWithoutKbs; -import org.thoughtcrime.securesms.registration.VerifyCodeWithRegistrationLockResponseProcessor; +import org.thoughtcrime.securesms.registration.VerifyResponse; +import org.thoughtcrime.securesms.registration.VerifyResponseProcessor; +import org.thoughtcrime.securesms.registration.VerifyResponseWithRegistrationLockProcessor; +import org.thoughtcrime.securesms.registration.VerifyResponseWithoutKbs; import org.thoughtcrime.securesms.util.Util; import org.whispersystems.signalservice.internal.ServiceResponse; -import org.whispersystems.signalservice.internal.push.VerifyAccountResponse; import io.reactivex.rxjava3.core.Single; @@ -103,24 +103,24 @@ public final class RegistrationViewModel extends BaseRegistrationViewModel { } @Override - protected Single> verifyAccountWithoutRegistrationLock() { + protected Single> verifyAccountWithoutRegistrationLock() { return verifyAccountRepository.verifyAccount(getRegistrationData()); } @Override - protected Single> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData) { + protected Single> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData) { return verifyAccountRepository.verifyAccountWithPin(getRegistrationData(), pin, kbsTokenData); } @Override - protected Single onVerifySuccess(@NonNull VerifyAccountResponseProcessor processor) { - return registrationRepository.registerAccountWithoutRegistrationLock(getRegistrationData(), processor.getResult()) - .map(VerifyAccountResponseWithoutKbs::new); + protected Single onVerifySuccess(@NonNull VerifyResponseProcessor processor) { + return registrationRepository.registerAccount(getRegistrationData(), processor.getResult()) + .map(VerifyResponseWithoutKbs::new); } @Override - protected Single onVerifySuccessWithRegistrationLock(@NonNull VerifyCodeWithRegistrationLockResponseProcessor processor, String pin) { - return registrationRepository.registerAccountWithRegistrationLock(getRegistrationData(), processor.getResult(), pin) + protected Single onVerifySuccessWithRegistrationLock(@NonNull VerifyResponseWithRegistrationLockProcessor processor, String pin) { + return registrationRepository.registerAccount(getRegistrationData(), processor.getResult()) .map(processor::updatedIfRegistrationFailed); }