mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-31 03:46:16 +00:00
feat: adding a force new configs flag and logic for timestamp handling / forced configs, fix issue with handling legacy messages
This commit is contained in:
@@ -94,14 +94,8 @@ import network.loki.messenger.libsession_util.util.Contact as LibSessionContact
|
||||
open class Storage(context: Context, helper: SQLCipherOpenHelper, private val configFactory: ConfigFactory) : Database(context, helper), StorageProtocol,
|
||||
ThreadDatabase.ConversationThreadUpdateListener {
|
||||
|
||||
// TODO: maybe add time here from formation / creation message
|
||||
override fun threadCreated(address: Address, threadId: Long) {
|
||||
if (!getRecipientApproved(address)) return // don't store unapproved / message requests
|
||||
if (getUserPublicKey() == address.serialize()) {
|
||||
Log.d("Loki-DBG", "NTS created, context:\n${Thread.currentThread().stackTrace.joinToString("\n")}")
|
||||
} else {
|
||||
Log.d("Loki-DBG", "Thread created ${address.serialize()}")
|
||||
}
|
||||
|
||||
val volatile = configFactory.convoVolatile ?: return
|
||||
if (address.isGroup) {
|
||||
@@ -491,7 +485,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
private fun updateUserGroups(userGroups: UserGroupsConfig) {
|
||||
val threadDb = DatabaseComponent.get(context).threadDatabase()
|
||||
val localUserPublicKey = getUserPublicKey() ?: return Log.w(
|
||||
"Loki-DBG",
|
||||
"Loki",
|
||||
"No user public key when trying to update user groups from config"
|
||||
)
|
||||
val communities = userGroups.allCommunityInfo()
|
||||
|
||||
@@ -596,6 +596,8 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(ConfigDatabase.CREATE_CONFIG_TABLE_COMMAND);
|
||||
db.execSQL(ConfigurationMessageUtilities.DELETE_INACTIVE_GROUPS);
|
||||
db.execSQL(ConfigurationMessageUtilities.DELETE_INACTIVE_ONE_TO_ONES);
|
||||
// TODO: remove this for release
|
||||
TextSecurePreferences.setForceNewConfig(context);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
@@ -6,13 +6,14 @@ import network.loki.messenger.libsession_util.Contacts
|
||||
import network.loki.messenger.libsession_util.ConversationVolatileConfig
|
||||
import network.loki.messenger.libsession_util.UserGroupsConfig
|
||||
import network.loki.messenger.libsession_util.UserProfile
|
||||
import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.ConfigFactoryProtocol
|
||||
import org.session.libsession.utilities.ConfigFactoryUpdateListener
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.thoughtcrime.securesms.database.ConfigDatabase
|
||||
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class ConfigFactory(
|
||||
private val context: Context,
|
||||
@@ -39,6 +40,8 @@ class ConfigFactory(
|
||||
private val userGroupsLock = Object()
|
||||
private var _userGroups: UserGroupsConfig? = null
|
||||
|
||||
private val isConfigForcedOn = TextSecurePreferences.hasForcedNewConfig(context)
|
||||
|
||||
private val listeners: MutableList<ConfigFactoryUpdateListener> = mutableListOf()
|
||||
fun registerListener(listener: ConfigFactoryUpdateListener) {
|
||||
listeners += listener
|
||||
@@ -50,7 +53,7 @@ class ConfigFactory(
|
||||
|
||||
override val user: UserProfile?
|
||||
get() = synchronized(userLock) {
|
||||
if (!ConfigBase.isNewConfigEnabled) return null
|
||||
if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null
|
||||
if (_userConfig == null) {
|
||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||
val userDump = configDatabase.retrieveConfigAndHashes(
|
||||
@@ -70,7 +73,7 @@ class ConfigFactory(
|
||||
|
||||
override val contacts: Contacts?
|
||||
get() = synchronized(contactsLock) {
|
||||
if (!ConfigBase.isNewConfigEnabled) return null
|
||||
if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null
|
||||
if (_contacts == null) {
|
||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||
val contactsDump = configDatabase.retrieveConfigAndHashes(
|
||||
@@ -90,7 +93,7 @@ class ConfigFactory(
|
||||
|
||||
override val convoVolatile: ConversationVolatileConfig?
|
||||
get() = synchronized(convoVolatileLock) {
|
||||
if (!ConfigBase.isNewConfigEnabled) return null
|
||||
if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null
|
||||
if (_convoVolatileConfig == null) {
|
||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||
val convoDump = configDatabase.retrieveConfigAndHashes(
|
||||
@@ -111,7 +114,7 @@ class ConfigFactory(
|
||||
|
||||
override val userGroups: UserGroupsConfig?
|
||||
get() = synchronized(userGroupsLock) {
|
||||
if (!ConfigBase.isNewConfigEnabled) return null
|
||||
if (!ConfigBase.isNewConfigEnabled(isConfigForcedOn, SnodeAPI.nowWithOffset)) return null
|
||||
if (_userGroups == null) {
|
||||
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
|
||||
val userGroupsDump = configDatabase.retrieveConfigAndHashes(
|
||||
@@ -174,7 +177,7 @@ class ConfigFactory(
|
||||
else -> throw UnsupportedOperationException("Can't support type of ${forConfigObject::class.simpleName} yet")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("Loki-DBG", e)
|
||||
Log.e("Loki", "failed to persist ${forConfigObject.javaClass.simpleName}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
||||
}
|
||||
|
||||
private fun updateLegacyConfigView() {
|
||||
binding.configOutdatedView.isVisible = ConfigBase.isNewConfigEnabled && textSecurePreferences.getHasLegacyConfig()
|
||||
binding.configOutdatedView.isVisible = ConfigBase.isNewConfigEnabled(textSecurePreferences.hasForcedNewConfig(), SnodeAPI.nowWithOffset)
|
||||
&& textSecurePreferences.getHasLegacyConfig()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.session.libsession.messaging.jobs.JobQueue
|
||||
import org.session.libsession.messaging.messages.Destination
|
||||
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||
import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.GroupUtil
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
@@ -25,7 +26,6 @@ import org.session.libsession.utilities.WindowDebouncer
|
||||
import org.session.libsignal.utilities.Hex
|
||||
import org.session.libsignal.utilities.toHexString
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase
|
||||
import org.thoughtcrime.securesms.database.GroupMemberDatabase
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
||||
import java.util.Timer
|
||||
@@ -53,7 +53,9 @@ object ConfigurationMessageUtilities {
|
||||
fun syncConfigurationIfNeeded(context: Context) {
|
||||
// add if check here to schedule new config job process and return early
|
||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context) ?: return
|
||||
if (ConfigBase.isNewConfigEnabled) {
|
||||
val forcedConfig = TextSecurePreferences.hasForcedNewConfig(context)
|
||||
val currentTime = SnodeAPI.nowWithOffset
|
||||
if (ConfigBase.isNewConfigEnabled(forcedConfig, currentTime)) {
|
||||
scheduleConfigSync(userPublicKey)
|
||||
return
|
||||
}
|
||||
@@ -81,7 +83,9 @@ object ConfigurationMessageUtilities {
|
||||
fun forceSyncConfigurationNowIfNeeded(context: Context): Promise<Unit, Exception> {
|
||||
// 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"))
|
||||
if (ConfigBase.isNewConfigEnabled) {
|
||||
val forcedConfig = TextSecurePreferences.hasForcedNewConfig(context)
|
||||
val currentTime = SnodeAPI.nowWithOffset
|
||||
if (ConfigBase.isNewConfigEnabled(forcedConfig, currentTime)) {
|
||||
// schedule job if none exist
|
||||
// don't schedule job if we already have one
|
||||
scheduleConfigSync(userPublicKey)
|
||||
|
||||
Reference in New Issue
Block a user