mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 12:44:38 +00:00
Split out backup and subscription error sheet handling.
This commit is contained in:
committed by
Nicholas Tinsley
parent
37a2d5fbca
commit
b55ba67b66
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user