mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Check remote subscription object to determine if a cancel is necessary.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -163,7 +163,7 @@ object RecurringInAppPaymentRepository {
|
||||
} else {
|
||||
Completable.complete()
|
||||
}
|
||||
}
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun getPaymentSourceTypeOfLatestSubscription(subscriberType: InAppPaymentSubscriberRecord.Type): Single<PaymentSourceType> {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user