From 30b339a482ee737f937756ac40122975edfdffd0 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Mon, 3 Jun 2024 13:30:50 -0300 Subject: [PATCH] Remove unnecessary subscriber call for manual cancel. --- .../subscription/InAppPaymentsRepository.kt | 3 +-- .../securesms/keyvalue/DonationsValues.kt | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt index 55fad99416..b2300a6639 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/InAppPaymentsRepository.kt @@ -298,8 +298,7 @@ object InAppPaymentsRepository { @JvmStatic @WorkerThread fun isUserManuallyCancelled(subscriberType: InAppPaymentSubscriberRecord.Type): Boolean { - val subscriber = getSubscriber(subscriberType) ?: return false - val latestSubscription = SignalDatabase.inAppPayments.getLatestInAppPaymentByType(subscriber.type.inAppPaymentType) + val latestSubscription = SignalDatabase.inAppPayments.getLatestInAppPaymentByType(subscriberType.inAppPaymentType) return if (latestSubscription == null) { SignalStore.donationsValues().isUserManuallyCancelled() diff --git a/app/src/main/java/org/thoughtcrime/securesms/keyvalue/DonationsValues.kt b/app/src/main/java/org/thoughtcrime/securesms/keyvalue/DonationsValues.kt index 2e46492666..8cad321dcd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/keyvalue/DonationsValues.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/keyvalue/DonationsValues.kt @@ -478,20 +478,22 @@ internal class DonationsValues internal constructor(store: KeyValueStore) : Sign @WorkerThread fun updateLocalStateForLocalSubscribe(subscriberType: InAppPaymentSubscriberRecord.Type) { synchronized(subscriberType) { - Log.d(TAG, "[updateLocalStateForLocalSubscribe] Clearing donation values.") + if (subscriberType == InAppPaymentSubscriberRecord.Type.DONATION) { + Log.d(TAG, "[updateLocalStateForLocalSubscribe] Clearing donation values.") - clearUserManuallyCancelled() - clearLevelOperations() - setUnexpectedSubscriptionCancelationChargeFailure(null) - unexpectedSubscriptionCancelationReason = null - unexpectedSubscriptionCancelationTimestamp = 0L - refreshSubscriptionRequestCredential() - clearSubscriptionReceiptCredential() + clearUserManuallyCancelled() + clearLevelOperations() + setUnexpectedSubscriptionCancelationChargeFailure(null) + unexpectedSubscriptionCancelationReason = null + unexpectedSubscriptionCancelationTimestamp = 0L + refreshSubscriptionRequestCredential() + clearSubscriptionReceiptCredential() - val expiredBadge = getExpiredBadge() - if (expiredBadge != null && expiredBadge.isSubscription()) { - Log.d(TAG, "[updateLocalStateForLocalSubscribe] Clearing expired badge.") - setExpiredBadge(null) + val expiredBadge = getExpiredBadge() + if (expiredBadge != null && expiredBadge.isSubscription()) { + Log.d(TAG, "[updateLocalStateForLocalSubscribe] Clearing expired badge.") + setExpiredBadge(null) + } } val subscriber = InAppPaymentsRepository.requireSubscriber(subscriberType)