Unify registration response models and processors.

main
Cody Henthorne 2023-01-06 10:08:01 -05:00 zatwierdzone przez Alex Hart
rodzic 3543a5ea24
commit 13f43799d6
12 zmienionych plików z 124 dodań i 171 usunięć

Wyświetl plik

@ -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<ServiceResponse<VerifyAccountResponse>> {
fun changeNumber(code: String, newE164: String, pniUpdateMode: Boolean = false): Single<ServiceResponse<VerifyResponse>> {
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<ServiceResponse<VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse>> {
): Single<ServiceResponse<VerifyResponse>> {
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) }
}

Wyświetl plik

@ -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<VerifyAccountResponseProcessor> {
override fun verifyCodeWithoutRegistrationLock(code: String): Single<VerifyResponseProcessor> {
return super.verifyCodeWithoutRegistrationLock(code)
.compose(ChangeNumberRepository::acquireReleaseChangeNumberLock)
.flatMap(this::attemptToUnlockChangeNumber)
}
override fun verifyCodeAndRegisterAccountWithRegistrationLock(pin: String): Single<VerifyCodeWithRegistrationLockResponseProcessor> {
override fun verifyCodeAndRegisterAccountWithRegistrationLock(pin: String): Single<VerifyResponseWithRegistrationLockProcessor> {
return super.verifyCodeAndRegisterAccountWithRegistrationLock(pin)
.compose(ChangeNumberRepository::acquireReleaseChangeNumberLock)
.flatMap(this::attemptToUnlockChangeNumber)
}
private fun <T : VerifyProcessor> attemptToUnlockChangeNumber(processor: T): Single<T> {
private fun <T : VerifyResponseProcessor> attemptToUnlockChangeNumber(processor: T): Single<T> {
return if (processor.hasResult() || processor.isServerSentError()) {
SignalStore.misc().unlockChangeNumber()
SignalStore.misc().clearPendingChangeNumberMetadata()
@ -152,30 +151,30 @@ class ChangeNumberViewModel(
}
}
override fun verifyAccountWithoutRegistrationLock(): Single<ServiceResponse<VerifyAccountResponse>> {
override fun verifyAccountWithoutRegistrationLock(): Single<ServiceResponse<VerifyResponse>> {
return changeNumberRepository.changeNumber(textCodeEntered, number.e164Number)
}
override fun verifyAccountWithRegistrationLock(pin: String, kbsTokenData: TokenData): Single<ServiceResponse<VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse>> {
override fun verifyAccountWithRegistrationLock(pin: String, kbsTokenData: TokenData): Single<ServiceResponse<VerifyResponse>> {
return changeNumberRepository.changeNumber(textCodeEntered, number.e164Number, pin, kbsTokenData)
}
@WorkerThread
override fun onVerifySuccess(processor: VerifyAccountResponseProcessor): Single<VerifyAccountResponseProcessor> {
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<VerifyCodeWithRegistrationLockResponseProcessor> {
override fun onVerifySuccess(processor: VerifyResponseProcessor): Single<VerifyResponseProcessor> {
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<VerifyResponseWithRegistrationLockProcessor> {
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)
}
}

Wyświetl plik

@ -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) {

Wyświetl plik

@ -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<ServiceResponse<VerifyAccountResponse>> registerAccountWithoutRegistrationLock(@NonNull RegistrationData registrationData,
@NonNull VerifyAccountResponse response)
public Single<ServiceResponse<VerifyResponse>> registerAccount(@NonNull RegistrationData registrationData,
@NonNull VerifyResponse response)
{
return registerAccount(registrationData, response, null, null);
}
public Single<ServiceResponse<VerifyAccountResponse>> registerAccountWithRegistrationLock(@NonNull RegistrationData registrationData,
@NonNull VerifyAccountWithRegistrationLockResponse response,
@NonNull String pin)
{
return registerAccount(registrationData, response.getVerifyAccountResponse(), pin, response.getKbsData());
}
private Single<ServiceResponse<VerifyAccountResponse>> registerAccount(@NonNull RegistrationData registrationData,
@NonNull VerifyAccountResponse response,
@Nullable String pin,
@Nullable KbsPinData kbsData)
{
return Single.<ServiceResponse<VerifyAccountResponse>>fromCallable(() -> {
return Single.<ServiceResponse<VerifyResponse>>fromCallable(() -> {
try {
registerAccountInternal(registrationData, response, pin, kbsData);
registerAccountInternal(registrationData, response.getVerifyAccountResponse(), response.getPin(), response.getKbsData());
JobManager jobManager = ApplicationDependencies.getJobManager();
jobManager.add(new DirectoryRefreshJob(false));

Wyświetl plik

@ -51,7 +51,7 @@ class VerifyAccountRepository(private val context: Application) {
}.subscribeOn(Schedulers.io())
}
fun verifyAccount(registrationData: RegistrationData): Single<ServiceResponse<VerifyAccountResponse>> {
fun verifyAccount(registrationData: RegistrationData): Single<ServiceResponse<VerifyResponse>> {
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<ServiceResponse<VerifyAccountWithRegistrationLockResponse>> {
fun verifyAccountWithPin(registrationData: RegistrationData, pin: String, tokenData: TokenData): Single<ServiceResponse<VerifyResponse>> {
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<VerifyAccountResponse>, kbsData: KbsPinData): ServiceResponse<VerifyAccountWithRegistrationLockResponse> {
return if (response.result.isPresent) {
ServiceResponse.forResult(VerifyAccountWithRegistrationLockResponse(response.result.get(), kbsData), 200, null)
} else {
ServiceResponse.coerceError(response)
}
}
}
}
}

Wyświetl plik

@ -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<VerifyAccountWithRegistrationLockResponse>,
val token: TokenData
) : ServiceResponseProcessor<VerifyAccountWithRegistrationLockResponse>(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<VerifyAccountResponse>): 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
}
}

Wyświetl plik

@ -1,6 +0,0 @@
package org.thoughtcrime.securesms.registration
interface VerifyProcessor {
fun hasResult(): Boolean
fun isServerSentError(): Boolean
}

Wyświetl plik

@ -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<VerifyAccountResponse>, kbsData: KbsPinData?, pin: String?): ServiceResponse<VerifyResponse> {
return if (response.result.isPresent) {
ServiceResponse.forResult(VerifyResponse(response.result.get(), kbsData, pin), 200, null)
} else {
ServiceResponse.coerceError(response)
}
}
}
}

Wyświetl plik

@ -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<VerifyAccountResponse>
) : ServiceResponseProcessor<VerifyAccountResponse>(response), VerifyProcessor {
sealed class VerifyResponseProcessor(response: ServiceResponse<VerifyResponse>) : ServiceResponseProcessor<VerifyResponse>(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<VerifyAccountResponse>) : VerifyAccountResponseProcessor(response) {
class VerifyResponseWithoutKbs(response: ServiceResponse<VerifyResponse>) : VerifyResponseProcessor(response) {
override fun isKbsLocked(): Boolean {
return registrationLock() && getLockedException().basicStorageCredentials == null
}
@ -56,11 +56,7 @@ class VerifyAccountResponseWithoutKbs(response: ServiceResponse<VerifyAccountRes
* Verify processor specific to verifying and successfully retrieving KBS information to
* later attempt to verif with registration lock data (pin).
*/
class VerifyAccountResponseWithSuccessfulKbs(
response: ServiceResponse<VerifyAccountResponse>,
override val tokenData: TokenData
) : VerifyAccountResponseProcessor(response) {
class VerifyResponseWithSuccessfulKbs(response: ServiceResponse<VerifyResponse>, 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<TokenData>) : VerifyAccountResponseProcessor(ServiceResponse.coerceError(response)) {
class VerifyResponseWithFailedKbs(response: ServiceResponse<TokenData>) : 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<VerifyResponse>, 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<VerifyResponse>): 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
}
}

Wyświetl plik

@ -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()) {

Wyświetl plik

@ -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<VerifyAccountResponseProcessor> verifyCodeWithoutRegistrationLock(@NonNull String code) {
public Single<VerifyResponseProcessor> 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<VerifyCodeWithRegistrationLockResponseProcessor> verifyCodeAndRegisterAccountWithRegistrationLock(@NonNull String pin) {
public Single<VerifyResponseWithRegistrationLockProcessor> 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<ServiceResponse<VerifyAccountResponse>> verifyAccountWithoutRegistrationLock();
protected abstract Single<ServiceResponse<VerifyResponse>> verifyAccountWithoutRegistrationLock();
protected abstract Single<ServiceResponse<VerifyAccountWithRegistrationLockResponse>> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData);
protected abstract Single<ServiceResponse<VerifyResponse>> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData);
protected abstract Single<VerifyAccountResponseProcessor> onVerifySuccess(@NonNull VerifyAccountResponseProcessor processor);
protected abstract Single<VerifyResponseProcessor> onVerifySuccess(@NonNull VerifyResponseProcessor processor);
protected abstract Single<VerifyCodeWithRegistrationLockResponseProcessor> onVerifySuccessWithRegistrationLock(@NonNull VerifyCodeWithRegistrationLockResponseProcessor processor, String pin);
protected abstract Single<VerifyResponseWithRegistrationLockProcessor> onVerifySuccessWithRegistrationLock(@NonNull VerifyResponseWithRegistrationLockProcessor processor, String pin);
}

Wyświetl plik

@ -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<ServiceResponse<VerifyAccountResponse>> verifyAccountWithoutRegistrationLock() {
protected Single<ServiceResponse<VerifyResponse>> verifyAccountWithoutRegistrationLock() {
return verifyAccountRepository.verifyAccount(getRegistrationData());
}
@Override
protected Single<ServiceResponse<VerifyAccountRepository.VerifyAccountWithRegistrationLockResponse>> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData) {
protected Single<ServiceResponse<VerifyResponse>> verifyAccountWithRegistrationLock(@NonNull String pin, @NonNull TokenData kbsTokenData) {
return verifyAccountRepository.verifyAccountWithPin(getRegistrationData(), pin, kbsTokenData);
}
@Override
protected Single<VerifyAccountResponseProcessor> onVerifySuccess(@NonNull VerifyAccountResponseProcessor processor) {
return registrationRepository.registerAccountWithoutRegistrationLock(getRegistrationData(), processor.getResult())
.map(VerifyAccountResponseWithoutKbs::new);
protected Single<VerifyResponseProcessor> onVerifySuccess(@NonNull VerifyResponseProcessor processor) {
return registrationRepository.registerAccount(getRegistrationData(), processor.getResult())
.map(VerifyResponseWithoutKbs::new);
}
@Override
protected Single<VerifyCodeWithRegistrationLockResponseProcessor> onVerifySuccessWithRegistrationLock(@NonNull VerifyCodeWithRegistrationLockResponseProcessor processor, String pin) {
return registrationRepository.registerAccountWithRegistrationLock(getRegistrationData(), processor.getResult(), pin)
protected Single<VerifyResponseWithRegistrationLockProcessor> onVerifySuccessWithRegistrationLock(@NonNull VerifyResponseWithRegistrationLockProcessor processor, String pin) {
return registrationRepository.registerAccount(getRegistrationData(), processor.getResult())
.map(processor::updatedIfRegistrationFailed);
}