mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Rewrite in-app-payment flows to prepare for backups support.
This commit is contained in:
committed by
Cody Henthorne
parent
b36b00a11c
commit
d719edf104
@@ -146,9 +146,10 @@ public class ApplicationMigrations {
|
||||
static final int PNP_LAUNCH = 102;
|
||||
static final int EMOJI_VERSION_10 = 103;
|
||||
static final int ATTACHMENT_HASH_BACKFILL = 104;
|
||||
static final int SUBSCRIBER_ID = 105;
|
||||
}
|
||||
|
||||
public static final int CURRENT_VERSION = 104;
|
||||
public static final int CURRENT_VERSION = 105;
|
||||
|
||||
/**
|
||||
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
|
||||
@@ -667,6 +668,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.ATTACHMENT_HASH_BACKFILL, new AttachmentHashBackfillMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.SUBSCRIBER_ID) {
|
||||
jobs.put(Version.SUBSCRIBER_ID, new SubscriberIdMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.migrations
|
||||
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository.toPaymentMethodType
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import java.util.Currency
|
||||
|
||||
/**
|
||||
* Migrates all subscriber ids from the key value store into the database.
|
||||
*/
|
||||
internal class SubscriberIdMigrationJob(
|
||||
parameters: Parameters = Parameters.Builder().build()
|
||||
) : MigrationJob(
|
||||
parameters
|
||||
) {
|
||||
|
||||
companion object {
|
||||
const val KEY = "SubscriberIdMigrationJob"
|
||||
}
|
||||
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun isUiBlocking(): Boolean = false
|
||||
|
||||
override fun performMigration() {
|
||||
Currency.getAvailableCurrencies().forEach { currency ->
|
||||
val subscriber = SignalStore.donationsValues().getSubscriber(currency)
|
||||
|
||||
if (subscriber != null) {
|
||||
SignalDatabase.inAppPaymentSubscribers.insertOrReplace(
|
||||
InAppPaymentSubscriberRecord(
|
||||
subscriber.subscriberId,
|
||||
subscriber.currencyCode,
|
||||
InAppPaymentSubscriberRecord.Type.DONATION,
|
||||
SignalStore.donationsValues().shouldCancelSubscriptionBeforeNextSubscribeAttempt,
|
||||
SignalStore.donationsValues().getSubscriptionPaymentSourceType().toPaymentMethodType()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun shouldRetry(e: Exception): Boolean = false
|
||||
|
||||
class Factory : Job.Factory<SubscriberIdMigrationJob> {
|
||||
override fun create(parameters: Parameters, serializedData: ByteArray?): SubscriberIdMigrationJob {
|
||||
return SubscriberIdMigrationJob(parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user