Show dialog when attempting to donate again while still processing previous donation.

This commit is contained in:
Cody Henthorne
2023-11-01 16:52:57 -04:00
committed by Greyson Parrelli
parent b96b99c1c4
commit 117bbdbcdf
10 changed files with 131 additions and 55 deletions

View File

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Application
import android.content.ContentValues
import android.database.Cursor
import androidx.core.content.contentValuesOf
import net.zetetic.database.sqlcipher.SQLiteDatabase
import net.zetetic.database.sqlcipher.SQLiteOpenHelper
import org.signal.core.util.CursorUtil
@@ -408,6 +409,11 @@ class JobDatabase(
}
}
/** Should only be used for debugging! */
fun debugResetBackoffInterval() {
writableDatabase.update(Jobs.TABLE_NAME, contentValuesOf(Jobs.NEXT_BACKOFF_INTERVAL to 0), null, null)
}
companion object {
private val TAG = Log.tag(JobDatabase::class.java)
private const val DATABASE_VERSION = 2

View File

@@ -3,7 +3,9 @@
package org.thoughtcrime.securesms.database.model
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList
import org.thoughtcrime.securesms.database.model.databaseprotos.PendingOneTimeDonation
import org.whispersystems.signalservice.internal.push.BodyRange
import kotlin.time.Duration.Companion.days
/**
* Collection of extensions to make working with database protos cleaner.
@@ -52,3 +54,25 @@ fun List<BodyRange>?.toBodyRangeList(): BodyRangeList? {
return builder.build()
}
fun PendingOneTimeDonation?.isPending(): Boolean {
return this != null && this.error == null && !this.isExpired
}
fun PendingOneTimeDonation?.isLongRunning(): Boolean {
return isPending() && this!!.paymentMethodType == PendingOneTimeDonation.PaymentMethodType.SEPA_DEBIT
}
val PendingOneTimeDonation.isExpired: Boolean
get() {
val pendingOneTimeBankTransferTimeout = 14.days
val pendingOneTimeNormalTimeout = 1.days
val timeout = if (paymentMethodType == PendingOneTimeDonation.PaymentMethodType.SEPA_DEBIT) {
pendingOneTimeBankTransferTimeout
} else {
pendingOneTimeNormalTimeout
}
return (timestamp + timeout.inWholeMilliseconds) < System.currentTimeMillis()
}