Implement happy path for backups subscriptions.

This commit is contained in:
Alex Hart
2024-09-25 16:14:41 -03:00
committed by Greyson Parrelli
parent c80ebd5658
commit 81d99c9d30
12 changed files with 132 additions and 155 deletions

View File

@@ -177,6 +177,11 @@ class InAppPaymentPurchaseTokenJob private constructor(
info("Scheduling retry.")
throw InAppPaymentRetryException()
}
else -> {
warning("An unknown error occurred.", applicationError)
throw IOException(applicationError)
}
}
}

View File

@@ -7,6 +7,7 @@ package org.thoughtcrime.securesms.jobs
import okio.ByteString.Companion.toByteString
import org.signal.core.util.logging.Log
import org.signal.donations.InAppPaymentType
import org.signal.libsignal.zkgroup.VerificationFailedException
import org.signal.libsignal.zkgroup.receipts.ReceiptCredential
import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialPresentation
@@ -65,11 +66,17 @@ class InAppPaymentRecurringContextJob private constructor(
* meaning the job will always load the freshest data it can about the payment.
*/
fun createJobChain(inAppPayment: InAppPaymentTable.InAppPayment, makePrimary: Boolean = false): Chain {
return AppDependencies.jobManager
.startChain(create(inAppPayment))
.then(InAppPaymentRedemptionJob.create(inAppPayment, makePrimary))
.then(RefreshOwnProfileJob())
.then(MultiDeviceProfileContentUpdateJob())
return if (inAppPayment.type == InAppPaymentType.RECURRING_BACKUP) {
AppDependencies.jobManager
.startChain(create(inAppPayment))
.then(InAppPaymentRedemptionJob.create(inAppPayment, makePrimary))
} else {
AppDependencies.jobManager
.startChain(create(inAppPayment))
.then(InAppPaymentRedemptionJob.create(inAppPayment, makePrimary))
.then(RefreshOwnProfileJob())
.then(MultiDeviceProfileContentUpdateJob())
}
}
}

View File

@@ -8,6 +8,7 @@ package org.thoughtcrime.securesms.jobs
import org.signal.core.util.logging.Log
import org.signal.donations.InAppPaymentType
import org.signal.libsignal.zkgroup.receipts.ReceiptCredentialPresentation
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.requireSubscriberType
import org.thoughtcrime.securesms.database.InAppPaymentTable
@@ -252,6 +253,12 @@ class InAppPaymentRedemptionJob private constructor(
)
)
)
if (inAppPayment.type == InAppPaymentType.RECURRING_BACKUP) {
Log.i(TAG, "Enabling backups and setting backup tier to PAID", true)
SignalStore.backup.areBackupsEnabled = true
SignalStore.backup.backupTier = MessageBackupTier.PAID
}
}
private fun <T> verifyServiceResponse(serviceResponse: ServiceResponse<T>, onFatalError: (Int) -> Unit = {}) {