Quiet down auth check job.

This commit is contained in:
Alex Hart
2024-06-21 15:28:58 -03:00
committed by Greyson Parrelli
parent 16c8b88f0f
commit 57a70c3085
3 changed files with 16 additions and 2 deletions

View File

@@ -238,11 +238,11 @@ public class ApplicationContext extends MultiDexApplication implements AppForegr
AppDependencies.getMegaphoneRepository().onAppForegrounded();
AppDependencies.getDeadlockDetector().start();
InAppPaymentKeepAliveJob.enqueueAndTrackTimeIfNecessary();
AppDependencies.getJobManager().add(new InAppPaymentAuthCheckJob());
FcmFetchManager.onForeground(this);
startAnrDetector();
SignalExecutors.BOUNDED.execute(() -> {
InAppPaymentAuthCheckJob.enqueueIfNeeded();
RemoteConfig.refreshIfNecessary();
RetrieveProfileJob.enqueueRoutineFetchIfNecessary();
executePendingContactSync();

View File

@@ -162,6 +162,13 @@ class InAppPaymentTable(context: Context, databaseHelper: SignalDatabase) : Data
AppDependencies.databaseObserver.notifyInAppPaymentsObservers(inAppPayment)
}
fun hasWaitingForAuth(): Boolean {
return readableDatabase
.exists(TABLE_NAME)
.where("$STATE = ?", State.serialize(State.WAITING_FOR_AUTHORIZATION))
.run()
}
fun getAllWaitingForAuth(): List<InAppPayment> {
return readableDatabase.select()
.from(TABLE_NAME)

View File

@@ -39,7 +39,7 @@ import kotlin.time.Duration.Companion.days
*/
class InAppPaymentAuthCheckJob private constructor(parameters: Parameters) : BaseJob(parameters), StripeApi.PaymentIntentFetcher, StripeApi.SetupIntentHelper {
constructor() : this(
private constructor() : this(
Parameters.Builder()
.addConstraint(NetworkConstraint.KEY)
.setMaxAttempts(Parameters.UNLIMITED)
@@ -51,6 +51,13 @@ class InAppPaymentAuthCheckJob private constructor(parameters: Parameters) : Bas
companion object {
private val TAG = Log.tag(InAppPaymentAuthCheckJob::class.java)
const val KEY = "InAppPaymentAuthCheckJob"
@JvmStatic
fun enqueueIfNeeded() {
if (SignalDatabase.inAppPayments.hasWaitingForAuth()) {
AppDependencies.jobManager.add(InAppPaymentAuthCheckJob())
}
}
}
private val stripeApi = StripeApi(Environment.Donations.STRIPE_CONFIGURATION, this, this, AppDependencies.okHttpClient)