diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/completed/TerminalDonationDelegate.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/completed/TerminalDonationDelegate.kt index 5abb1484ba..a126fcd727 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/completed/TerminalDonationDelegate.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/completed/TerminalDonationDelegate.kt @@ -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) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/InAppPaymentTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/InAppPaymentTable.kt index 9f042ba711..f3c5ac2ecd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/InAppPaymentTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/InAppPaymentTable.kt @@ -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 { + /** + * Retrieves all InAppPayment objects for donations that have been marked NOTIFIED = 0, and then marks them + * all as notified. + */ + fun consumeDonationPaymentsToNotifyUser(): List { 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 { + 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 }