From 341c47461051653d4a2edaa7092ae3365c4dc603 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 19 Jun 2024 14:57:35 -0400 Subject: [PATCH] Remove some indirect database reads from backup export. --- .../v2/processor/AccountDataProcessor.kt | 24 +++++++++---------- .../v2/processor/RecipientBackupProcessor.kt | 3 +-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/AccountDataProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/AccountDataProcessor.kt index 2a92523f09..f5a4a21e8a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/AccountDataProcessor.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/AccountDataProcessor.kt @@ -29,28 +29,26 @@ import org.whispersystems.signalservice.api.storage.StorageRecordProtoUtil.defau import org.whispersystems.signalservice.api.subscriptions.SubscriberId import org.whispersystems.signalservice.api.util.UuidUtil import java.util.Currency -import kotlin.jvm.optionals.getOrNull object AccountDataProcessor { fun export(db: SignalDatabase, emitter: BackupFrameEmitter) { val context = AppDependencies.application - // TODO [backup] Need to get it from the db snapshot - val self = Recipient.self().fresh() - val record = db.recipientTable.getRecordForSync(self.id) + val selfId = db.recipientTable.getByAci(SignalStore.account().aci!!).get() + val selfRecord = db.recipientTable.getRecordForSync(selfId)!! - // TODO [backup] Need to get it from the db snapshot - val subscriber: InAppPaymentSubscriberRecord? = InAppPaymentsRepository.getSubscriber(InAppPaymentSubscriberRecord.Type.DONATION) + val donationCurrency = SignalStore.donationsValues().getSubscriptionCurrency(InAppPaymentSubscriberRecord.Type.DONATION) + val donationSubscriber = SignalDatabase.inAppPaymentSubscribers.getByCurrencyCode(donationCurrency.currencyCode, InAppPaymentSubscriberRecord.Type.DONATION) emitter.emit( Frame( account = AccountData( - profileKey = self.profileKey?.toByteString() ?: EMPTY, - givenName = self.profileName.givenName, - familyName = self.profileName.familyName, - avatarUrlPath = self.profileAvatar ?: "", - username = self.username.getOrNull(), + profileKey = selfRecord.profileKey?.toByteString() ?: EMPTY, + givenName = selfRecord.signalProfileName.givenName, + familyName = selfRecord.signalProfileName.familyName, + avatarUrlPath = selfRecord.signalProfileAvatar ?: "", + username = selfRecord.username, accountSettings = AccountData.AccountSettings( storyViewReceiptsEnabled = SignalStore.storyValues().viewedReceiptsEnabled, typingIndicators = TextSecurePreferences.isTypingIndicatorsEnabled(context), @@ -71,8 +69,8 @@ object AccountDataProcessor { hasCompletedUsernameOnboarding = SignalStore.uiHints().hasCompletedUsernameOnboarding() ), donationSubscriberData = AccountData.SubscriberData( - subscriberId = subscriber?.subscriberId?.bytes?.toByteString() ?: defaultAccountRecord.subscriberId, - currencyCode = subscriber?.currency?.currencyCode ?: defaultAccountRecord.subscriberCurrencyCode, + subscriberId = donationSubscriber?.subscriberId?.bytes?.toByteString() ?: defaultAccountRecord.subscriberId, + currencyCode = donationSubscriber?.currency?.currencyCode ?: defaultAccountRecord.subscriberCurrencyCode, manuallyCancelled = InAppPaymentsRepository.isUserManuallyCancelled(InAppPaymentSubscriberRecord.Type.DONATION) ) ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/RecipientBackupProcessor.kt b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/RecipientBackupProcessor.kt index edc870621e..cf80b7fba7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/RecipientBackupProcessor.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/backup/v2/processor/RecipientBackupProcessor.kt @@ -31,8 +31,7 @@ object RecipientBackupProcessor { val TAG = Log.tag(RecipientBackupProcessor::class.java) fun export(db: SignalDatabase, state: ExportState, emitter: BackupFrameEmitter) { - // TODO [backup] Need to get it from the db snapshot - val selfId = Recipient.self().id.toLong() + val selfId = db.recipientTable.getByAci(SignalStore.account().aci!!).get().toLong() val releaseChannelId = SignalStore.releaseChannelValues().releaseChannelRecipientId if (releaseChannelId != null) { emitter.emit(