Split out backup and subscription error sheet handling.

This commit is contained in:
Alex Hart
2024-06-25 14:53:24 -03:00
committed by Nicholas Tinsley
parent 37a2d5fbca
commit b55ba67b66
2 changed files with 30 additions and 5 deletions

View File

@@ -69,7 +69,7 @@ class TerminalDonationDelegate(
private fun handleInAppPaymentSheets() {
lifecycleDisposable += Single.fromCallable {
SignalDatabase.inAppPayments.consumeInAppPaymentsToNotifyUser()
SignalDatabase.inAppPayments.consumeDonationPaymentsToNotifyUser()
}.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeBy { inAppPayments ->
for (payment in inAppPayments) {
if (payment.data.error == null && payment.state == InAppPaymentTable.State.END) {

View File

@@ -28,7 +28,6 @@ import org.signal.core.util.requireNonNullBlob
import org.signal.core.util.requireString
import org.signal.core.util.select
import org.signal.core.util.update
import org.signal.core.util.updateAll
import org.signal.core.util.withinTransaction
import org.signal.donations.InAppPaymentType
import org.thoughtcrime.securesms.database.model.databaseprotos.InAppPaymentData
@@ -177,15 +176,41 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
.readToList { InAppPayment.deserialize(it) }
}
fun consumeInAppPaymentsToNotifyUser(): List<InAppPayment> {
/**
* Retrieves all InAppPayment objects for donations that have been marked NOTIFIED = 0, and then marks them
* all as notified.
*/
fun consumeDonationPaymentsToNotifyUser(): List<InAppPayment> {
return writableDatabase.withinTransaction { db ->
val payments = db.select()
.from(TABLE_NAME)
.where("$NOTIFIED = ?", 0)
.where("$NOTIFIED = ? AND $TYPE != ?", 0, InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
.run()
.readToList(mapper = { InAppPayment.deserialize(it) })
db.updateAll(TABLE_NAME).values(NOTIFIED to 1).run()
db.update(TABLE_NAME).values(NOTIFIED to 1)
.where("$TYPE != ?", InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
.run()
payments
}
}
/**
* Retrieves all InAppPayment objects for backups that have been marked NOTIFIED = 0, and then marks them
* all as notified.
*/
fun consumeBackupPaymentsToNotifyUser(): List<InAppPayment> {
return writableDatabase.withinTransaction { db ->
val payments = db.select()
.from(TABLE_NAME)
.where("$NOTIFIED = ? AND $TYPE = ?", 0, InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
.run()
.readToList(mapper = { InAppPayment.deserialize(it) })
db.update(TABLE_NAME).values(NOTIFIED to 1)
.where("$TYPE = ?", InAppPaymentType.serialize(InAppPaymentType.RECURRING_BACKUP))
.run()
payments
}