Fix NPE when canceling a donation.
This commit is contained in:
parent
c480512600
commit
58b6e49aae
2 changed files with 19 additions and 6 deletions
|
@ -40,6 +40,7 @@ import org.thoughtcrime.securesms.dependencies.AppDependencies
|
|||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription
|
||||
import org.whispersystems.signalservice.api.subscriptions.SubscriberId
|
||||
import org.whispersystems.signalservice.internal.push.DonationProcessor
|
||||
import org.whispersystems.signalservice.internal.push.exceptions.DonationProcessorError
|
||||
import java.security.SecureRandom
|
||||
|
@ -307,19 +308,29 @@ object InAppPaymentsRepository {
|
|||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@WorkerThread
|
||||
fun setShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriber: InAppPaymentSubscriberRecord, shouldCancel: Boolean) {
|
||||
setShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriber.type, subscriber.subscriberId, shouldCancel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether we should force a cancellation before our next subscription attempt. This is to help clean up
|
||||
* bad state in some edge cases.
|
||||
*/
|
||||
@JvmStatic
|
||||
@WorkerThread
|
||||
fun setShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriber: InAppPaymentSubscriberRecord, shouldCancel: Boolean) {
|
||||
if (subscriber.type == InAppPaymentSubscriberRecord.Type.DONATION) {
|
||||
fun setShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriberType: InAppPaymentSubscriberRecord.Type, subscriberId: SubscriberId?, shouldCancel: Boolean) {
|
||||
if (subscriberType == InAppPaymentSubscriberRecord.Type.DONATION) {
|
||||
SignalStore.donationsValues().shouldCancelSubscriptionBeforeNextSubscribeAttempt = shouldCancel
|
||||
}
|
||||
|
||||
if (subscriberId == null) {
|
||||
return
|
||||
}
|
||||
|
||||
SignalDatabase.inAppPaymentSubscribers.setRequiresCancel(
|
||||
subscriberId = subscriber.subscriberId,
|
||||
subscriberId = subscriberId,
|
||||
requiresCancel = shouldCancel
|
||||
)
|
||||
}
|
||||
|
|
|
@ -461,9 +461,11 @@ internal class DonationsValues internal constructor(store: KeyValueStore) : Sign
|
|||
}
|
||||
}
|
||||
|
||||
val subscriber = InAppPaymentsRepository.requireSubscriber(subscriberType)
|
||||
InAppPaymentsRepository.setShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriber, true)
|
||||
SignalDatabase.inAppPayments.markSubscriptionManuallyCanceled(subscriberId = subscriber.subscriberId)
|
||||
val subscriber = InAppPaymentsRepository.getSubscriber(subscriberType)
|
||||
InAppPaymentsRepository.setShouldCancelSubscriptionBeforeNextSubscribeAttempt(subscriberType, subscriber?.subscriberId, true)
|
||||
if (subscriber != null) {
|
||||
SignalDatabase.inAppPayments.markSubscriptionManuallyCanceled(subscriberId = subscriber.subscriberId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue