Check remote subscription object to determine if a cancel is necessary.

This commit is contained in:
Alex Hart
2024-08-16 16:28:06 -03:00
committed by mtang-signal
parent 1f8481d287
commit 82443af8f7
3 changed files with 15 additions and 4 deletions

View File

@@ -406,18 +406,28 @@ object InAppPaymentsRepository {
/**
* Retrieves whether or not we should force a cancel before next subscribe attempt for in app payments of the given
* type. This method will first check the database, and then fall back on the deprecated SignalStore value.
* type. This method will first check the database, and then fall back on the deprecated SignalStore value. This method
* will also access and check the current subscriber data, if it exists.
*/
@JvmStatic
@WorkerThread
fun getShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriberType: InAppPaymentSubscriberRecord.Type): Boolean {
val latestSubscriber = getSubscriber(subscriberType)
return latestSubscriber?.requiresCancel ?: if (subscriberType == InAppPaymentSubscriberRecord.Type.DONATION) {
val localState = latestSubscriber?.requiresCancel ?: if (subscriberType == InAppPaymentSubscriberRecord.Type.DONATION) {
SignalStore.inAppPayments.shouldCancelSubscriptionBeforeNextSubscribeAttempt
} else {
false
}
if (latestSubscriber != null) {
val remoteState = AppDependencies.donationsService.getSubscription(latestSubscriber.subscriberId)
val result = remoteState.result.getOrNull() ?: return localState
return result.activeSubscription?.isCanceled ?: localState
}
return localState
}
/**

View File

@@ -163,7 +163,7 @@ object RecurringInAppPaymentRepository {
} else {
Completable.complete()
}
}
}.subscribeOn(Schedulers.io())
}
fun getPaymentSourceTypeOfLatestSubscription(subscriberType: InAppPaymentSubscriberRecord.Type): Single<PaymentSourceType> {

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.components.settings.app.subscription.manage
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.CompositeDisposable
@@ -66,7 +67,7 @@ class ManageDonationsViewModel : ViewModel() {
disposables += Single.fromCallable {
InAppPaymentsRepository.getShouldCancelSubscriptionBeforeNextSubscribeAttempt(InAppPaymentSubscriberRecord.Type.DONATION)
}.subscribeBy { requiresCancel ->
}.subscribeOn(Schedulers.io()).subscribeBy { requiresCancel ->
store.update {
it.copy(subscriberRequiresCancel = requiresCancel)
}