From 336604b9e5381ee82c7ba5efe573fa96291da800 Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Wed, 8 Feb 2023 17:31:33 +1100 Subject: [PATCH] refactor: moving some properties around so we have access in libsession --- .../securesms/ApplicationContext.java | 4 +++- .../util/ConfigurationMessageUtilities.kt | 7 +++---- .../loki/messenger/libsession_util/Config.kt | 3 +++ .../messaging/MessagingModuleConfiguration.kt | 4 +++- .../messaging/jobs/ConfigurationSyncJob.kt | 19 ++++++++++++++++++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index 9894c7e01d..b0d4a9cf9f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -207,7 +207,9 @@ public class ApplicationContext extends Application implements DefaultLifecycleO messagingModuleConfiguration = new MessagingModuleConfiguration(this, storage, messageDataProvider, - ()-> KeyPairUtilities.INSTANCE.getUserED25519KeyPair(this)); + ()-> KeyPairUtilities.INSTANCE.getUserED25519KeyPair(this), + configFactory + ); // migrate session open group data OpenGroupMigrator.migrate(getDatabaseComponent()); // end migration 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 8180039e8a..6ba15352d7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.util import android.content.Context +import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.Contacts import network.loki.messenger.libsession_util.UserProfile import network.loki.messenger.libsession_util.util.Contact @@ -15,12 +16,10 @@ import org.session.libsession.utilities.TextSecurePreferences object ConfigurationMessageUtilities { - const val isNewConfigEnabled = true - @JvmStatic fun syncConfigurationIfNeeded(context: Context) { // add if check here to schedule new config job process and return early - if (isNewConfigEnabled) { + if (ConfigBase.isNewConfigEnabled) { // schedule job if none exist TODO() } @@ -48,7 +47,7 @@ object ConfigurationMessageUtilities { fun forceSyncConfigurationNowIfNeeded(context: Context): Promise { // add if check here to schedule new config job process and return early - if (isNewConfigEnabled) { + if (ConfigBase.isNewConfigEnabled) { // schedule job if none exist TODO() } diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt index 50454f6b37..7fa62241a9 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/Config.kt @@ -12,6 +12,9 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) { System.loadLibrary("session_util") } external fun kindFor(configNamespace: Int): Class + + const val isNewConfigEnabled = true + } external fun dirty(): Boolean diff --git a/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt b/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt index 37c391dfd6..0437196772 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/MessagingModuleConfiguration.kt @@ -4,12 +4,14 @@ import android.content.Context import com.goterl.lazysodium.utils.KeyPair import org.session.libsession.database.MessageDataProvider import org.session.libsession.database.StorageProtocol +import org.session.libsession.utilities.ConfigFactoryProtocol class MessagingModuleConfiguration( val context: Context, val storage: StorageProtocol, val messageDataProvider: MessageDataProvider, - val getUserED25519KeyPair: ()-> KeyPair? + val getUserED25519KeyPair: () -> KeyPair?, + val configFactory: ConfigFactoryProtocol ) { companion object { diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt index 1c97630d0b..739d61b2da 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/ConfigurationSyncJob.kt @@ -1,7 +1,10 @@ package org.session.libsession.messaging.jobs +import network.loki.messenger.libsession_util.ConfigBase +import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.messages.Destination import org.session.libsession.messaging.utilities.Data +import org.session.libsignal.utilities.Log // only contact (self) and closed group destinations will be supported data class ConfigurationSyncJob(val destination: Destination): Job { @@ -12,7 +15,21 @@ data class ConfigurationSyncJob(val destination: Destination): Job { override val maxFailureCount: Int = 1 override suspend fun execute() { - TODO("Not yet implemented") + val userEdKeyPair = MessagingModuleConfiguration.shared.getUserED25519KeyPair() + if (destination is Destination.ClosedGroup + || !ConfigBase.isNewConfigEnabled + || userEdKeyPair == null + ) { + // TODO: currently we only deal with single destination until closed groups refactor / implement LCG + Log.w(TAG, "Not handling config sync job, TODO") + delegate?.handleJobSucceeded(this) + return + } + + val configFactory = MessagingModuleConfiguration.shared.configFactory + + + } override fun serialize(): Data {