diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt index 867a578c77..4d53204f07 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ConfigDatabase.kt @@ -19,10 +19,6 @@ class ConfigDatabase(context: Context, helper: SQLCipherOpenHelper): Database(co "CREATE TABLE $TABLE_NAME ($VARIANT TEXT NOT NULL, $PUBKEY TEXT NOT NULL, $DATA BLOB, $COMBINED_MESSAGE_HASHES TEXT, PRIMARY KEY($VARIANT, $PUBKEY));" private const val VARIANT_WHERE = "$VARIANT = ?" private const val VARIANT_AND_PUBKEY_WHERE = "$VARIANT = ? AND $PUBKEY = ?" - - const val USER_KEY = "user" - const val CONTACTS_KEY = "contacts" - // conversations use publicKey / URL } fun storeConfig(variant: String, publicKey: String, data: ByteArray) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt index 7e6c94e580..e6bf91e8e0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt @@ -3,9 +3,10 @@ package org.thoughtcrime.securesms.dependencies import network.loki.messenger.libsession_util.Contacts import network.loki.messenger.libsession_util.UserProfile import org.session.libsession.utilities.ConfigFactoryProtocol +import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage import org.thoughtcrime.securesms.database.ConfigDatabase -class ConfigFactory(private val configDatabase: ConfigDatabase, private val maybeGetUserEdSecretKey: ()->ByteArray?): +class ConfigFactory(private val configDatabase: ConfigDatabase, private val maybeGetUserInfo: ()->Pair?): ConfigFactoryProtocol { fun keyPairChanged() { // this should only happen restoring or clearing data @@ -22,8 +23,8 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb override val userConfig: UserProfile? = synchronized(userLock) { if (_userConfig == null) { - val secretKey = maybeGetUserEdSecretKey() ?: return@synchronized null - val userDump = configDatabase.retrieveConfig(ConfigDatabase.USER_KEY) + val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null + val userDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey) _userConfig = if (userDump != null) { UserProfile.newInstance(secretKey, userDump) } else { @@ -35,8 +36,8 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb override val contacts: Contacts? = synchronized(contactLock) { if (_contacts == null) { - val secretKey = maybeGetUserEdSecretKey() ?: return@synchronized null - val contactsDump = configDatabase.retrieveConfig(ConfigDatabase.CONTACTS_KEY) + val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null + val contactsDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.CONTACTS.name, publicKey) _contacts = if (contactsDump != null) { Contacts.newInstance(secretKey, contactsDump) } else { @@ -49,12 +50,14 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb override fun saveUserConfigDump() { val dumped = userConfig?.dump() ?: return - configDatabase.storeConfig(ConfigDatabase.USER_KEY, dumped) + val (_, publicKey) = maybeGetUserInfo() ?: return + configDatabase.storeConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey, dumped) } override fun saveContactConfigDump() { val dumped = contacts?.dump() ?: return - configDatabase.storeConfig(ConfigDatabase.CONTACTS_KEY, dumped) + val (_, publicKey) = maybeGetUserInfo() ?: return + configDatabase.storeConfig(SharedConfigMessage.Kind.CONTACTS.name, publicKey, dumped) } } \ No newline at end of file