mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Add check for KEEP_ALIVE job state to allow for re-submission.
This commit is contained in:
@@ -286,19 +286,6 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
|
||||
.run()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether there are any pending donations in the database.
|
||||
*/
|
||||
fun hasPending(type: InAppPaymentType): Boolean {
|
||||
return readableDatabase.exists(TABLE_NAME)
|
||||
.where(
|
||||
"$STATE = ? AND $TYPE = ?",
|
||||
State.serialize(State.PENDING),
|
||||
InAppPaymentType.serialize(type)
|
||||
)
|
||||
.run()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves from the database the latest payment of the given type that is either in the PENDING or WAITING_FOR_AUTHORIZATION state.
|
||||
*/
|
||||
|
||||
@@ -47,6 +47,7 @@ class InAppPaymentKeepAliveJob private constructor(
|
||||
|
||||
private val TIMEOUT = 3.days
|
||||
|
||||
const val KEEP_ALIVE = "keep-alive"
|
||||
private const val DATA_TYPE = "type"
|
||||
|
||||
fun create(type: InAppPaymentSubscriberRecord.Type): Job {
|
||||
@@ -131,11 +132,6 @@ class InAppPaymentKeepAliveJob private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
if (SignalDatabase.inAppPayments.hasPending(type.inAppPaymentType)) {
|
||||
info(type, "Already trying to redeem $type. Exiting.")
|
||||
return
|
||||
}
|
||||
|
||||
val activeInAppPayment = getActiveInAppPayment(subscriber, subscription)
|
||||
if (activeInAppPayment == null) {
|
||||
warn(type, "Failed to generate active in-app payment. Exiting")
|
||||
@@ -144,7 +140,6 @@ class InAppPaymentKeepAliveJob private constructor(
|
||||
|
||||
if (activeInAppPayment.state == InAppPaymentTable.State.END) {
|
||||
warn(type, "Active in-app payment is in the END state. Cannot proceed.")
|
||||
warn(type, "Active in-app payment error state: ${activeInAppPayment.data.error}")
|
||||
warn(type, "Active in-app payment cancel state: ${activeInAppPayment.data.cancellation}")
|
||||
return
|
||||
}
|
||||
@@ -275,6 +270,17 @@ class InAppPaymentKeepAliveJob private constructor(
|
||||
|
||||
MultiDeviceSubscriptionSyncRequestJob.enqueue()
|
||||
SignalDatabase.inAppPayments.getById(inAppPaymentId)
|
||||
} else if (current.state == InAppPaymentTable.State.PENDING && current.data.error?.data_ == KEEP_ALIVE) {
|
||||
info(type, "Found failed keep-alive. Retrying.")
|
||||
SignalDatabase.inAppPayments.update(
|
||||
current.copy(
|
||||
data = current.data.copy(
|
||||
error = null
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
SignalDatabase.inAppPayments.getById(current.id)
|
||||
} else {
|
||||
current
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ class InAppPaymentRecurringContextJob private constructor(
|
||||
data = inAppPayment.data.copy(
|
||||
error = InAppPaymentData.Error(
|
||||
type = InAppPaymentData.Error.Type.PAYMENT_PROCESSING,
|
||||
data_ = "keep-alive"
|
||||
data_ = InAppPaymentKeepAliveJob.KEEP_ALIVE
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user