mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-02 00:17:41 +01:00
Move fetch of first emission to the observeInAppPaymentRedemption call.
This commit is contained in:
@@ -588,12 +588,14 @@ object InAppPaymentsRepository {
|
||||
val fromDatabase: Observable<DonationRedemptionJobStatus> = Observable.create { emitter ->
|
||||
val observer = InAppPaymentObserver {
|
||||
val latestInAppPayment = SignalDatabase.inAppPayments.getLatestInAppPaymentByType(type)
|
||||
|
||||
emitter.onNext(Optional.ofNullable(latestInAppPayment))
|
||||
}
|
||||
|
||||
AppDependencies.databaseObserver.registerInAppPaymentObserver(observer)
|
||||
emitter.setCancellable { AppDependencies.databaseObserver.unregisterObserver(observer) }
|
||||
|
||||
val latestInAppPayment = SignalDatabase.inAppPayments.getLatestInAppPaymentByType(type)
|
||||
emitter.onNext(Optional.ofNullable(latestInAppPayment))
|
||||
}.switchMap { inAppPaymentOptional ->
|
||||
val inAppPayment = inAppPaymentOptional.getOrNull() ?: return@switchMap Observable.just(DonationRedemptionJobStatus.None)
|
||||
|
||||
|
||||
@@ -66,8 +66,6 @@ class ManageDonationsViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
updateRecurringDonationState()
|
||||
|
||||
InAppPaymentsRepository.observeInAppPaymentRedemption(InAppPaymentType.RECURRING_DONATION)
|
||||
.asFlow()
|
||||
.collect { redemptionStatus ->
|
||||
@@ -79,6 +77,7 @@ class ManageDonationsViewModel : ViewModel() {
|
||||
|
||||
store.update { manageDonationsState ->
|
||||
manageDonationsState.copy(
|
||||
isLoaded = true,
|
||||
nonVerifiedMonthlyDonation = if (redemptionStatus is DonationRedemptionJobStatus.PendingExternalVerification) redemptionStatus.nonVerifiedMonthlyDonation else null,
|
||||
subscriptionRedemptionState = deriveRedemptionState(redemptionStatus, latestPayment),
|
||||
activeSubscription = activeSubscription
|
||||
@@ -160,21 +159,6 @@ class ManageDonationsViewModel : ViewModel() {
|
||||
)
|
||||
}
|
||||
|
||||
private fun updateRecurringDonationState() {
|
||||
val latestPayment = SignalDatabase.inAppPayments.getLatestInAppPaymentByType(InAppPaymentType.RECURRING_DONATION)
|
||||
|
||||
val activeSubscription: InAppPaymentTable.InAppPayment? = latestPayment?.let {
|
||||
if (it.data.cancellation == null) it else null
|
||||
}
|
||||
|
||||
store.update { manageDonationsState ->
|
||||
manageDonationsState.copy(
|
||||
isLoaded = true,
|
||||
activeSubscription = activeSubscription
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deriveRedemptionState(status: DonationRedemptionJobStatus, latestPayment: InAppPaymentTable.InAppPayment?): ManageDonationsState.RedemptionState {
|
||||
return when (status) {
|
||||
DonationRedemptionJobStatus.None -> ManageDonationsState.RedemptionState.NONE
|
||||
|
||||
Reference in New Issue
Block a user