mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-20 15:48:39 +00:00
feat: add in more config factory for volatile
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.dependencies
|
||||
|
||||
import network.loki.messenger.libsession_util.Contacts
|
||||
import network.loki.messenger.libsession_util.ConversationVolatileConfig
|
||||
import network.loki.messenger.libsession_util.UserProfile
|
||||
import org.session.libsession.utilities.ConfigFactoryProtocol
|
||||
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
|
||||
@@ -12,16 +13,20 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb
|
||||
fun keyPairChanged() { // this should only happen restoring or clearing data
|
||||
_userConfig?.free()
|
||||
_contacts?.free()
|
||||
_convoVolatileConfig?.free()
|
||||
_userConfig = null
|
||||
_contacts = null
|
||||
_convoVolatileConfig = null
|
||||
}
|
||||
|
||||
private val userLock = Object()
|
||||
private var _userConfig: UserProfile? = null
|
||||
private val contactLock = Object()
|
||||
private var _contacts: Contacts? = null
|
||||
private val convoVolatileLock = Object()
|
||||
private var _convoVolatileConfig: ConversationVolatileConfig? = null
|
||||
|
||||
override val userConfig: UserProfile? = synchronized(userLock) {
|
||||
override val user: UserProfile? = synchronized(userLock) {
|
||||
if (_userConfig == null) {
|
||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||
val userDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey)
|
||||
@@ -47,9 +52,22 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb
|
||||
_contacts
|
||||
}
|
||||
|
||||
override val convoVolatile: ConversationVolatileConfig? = synchronized(convoVolatileLock) {
|
||||
if (_convoVolatileConfig == null) {
|
||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||
val convoDump = configDatabase.retrieveConfig(SharedConfigMessage.Kind.CONVO_INFO_VOLATILE.name, publicKey)
|
||||
_convoVolatileConfig = if (convoDump != null) {
|
||||
ConversationVolatileConfig.newInstance(secretKey, convoDump)
|
||||
} else {
|
||||
ConversationVolatileConfig.newInstance(secretKey)
|
||||
}
|
||||
}
|
||||
_convoVolatileConfig
|
||||
}
|
||||
|
||||
|
||||
override fun saveUserConfigDump() {
|
||||
val dumped = userConfig?.dump() ?: return
|
||||
val dumped = user?.dump() ?: return
|
||||
val (_, publicKey) = maybeGetUserInfo() ?: return
|
||||
configDatabase.storeConfig(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey, dumped)
|
||||
}
|
||||
@@ -60,4 +78,9 @@ class ConfigFactory(private val configDatabase: ConfigDatabase, private val mayb
|
||||
configDatabase.storeConfig(SharedConfigMessage.Kind.CONTACTS.name, publicKey, dumped)
|
||||
}
|
||||
|
||||
override fun saveConvoVolatileConfigDump() {
|
||||
val dumped = convoVolatile?.dump() ?: return
|
||||
val (_, publicKey) = maybeGetUserInfo() ?: return
|
||||
configDatabase.storeConfig(SharedConfigMessage.Kind.CONVO_INFO_VOLATILE.name, publicKey, dumped)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user