From fb21f58cbd509110f56e33ed3bc5e53f653a72d2 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Fri, 10 Feb 2023 16:46:39 +1100 Subject: [PATCH] feat: add forced config sync --- .../securesms/util/ConfigurationMessageUtilities.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt index 6773b2afff..2d43992c9c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt @@ -56,11 +56,19 @@ object ConfigurationMessageUtilities { fun forceSyncConfigurationNowIfNeeded(context: Context): Promise { // add if check here to schedule new config job process and return early + val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return Promise.ofFail(NullPointerException("User Public Key is null")) + val storage = MessagingModuleConfiguration.shared.storage if (ConfigBase.isNewConfigEnabled) { // schedule job if none exist - TODO() + // don't schedule job if we already have one + val ourDestination = Destination.Contact(userPublicKey) + if (storage.getConfigSyncJob(ourDestination) != null) return Promise.ofFail(NullPointerException("A job is already pending or in progress, don't schedule another job")) + val newConfigSync = ConfigurationSyncJob(ourDestination) + Log.d("Loki", "Scheduling new ConfigurationSyncJob") + JobQueue.shared.add(newConfigSync) + // treat this promise as succeeding now (so app continues running and doesn't block UI) + return Promise.ofSuccess(Unit) } - val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return Promise.ofSuccess(Unit) val contacts = ContactUtilities.getAllContacts(context).filter { recipient -> !recipient.isGroupRecipient && !recipient.name.isNullOrEmpty() && !recipient.isLocalNumber && recipient.address.serialize().isNotEmpty() }.map { recipient ->