fix: getters weren't getters properly in the config factory, fixed new onboarding from configs

This commit is contained in:
0x330a 2023-02-21 17:50:11 +11:00
parent e159e4ad52
commit 548862c37d
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
5 changed files with 23 additions and 6 deletions

View File

@ -116,6 +116,7 @@ import kotlin.Unit;
import kotlinx.coroutines.Job;
import network.loki.messenger.BuildConfig;
import network.loki.messenger.libsession_util.ConfigBase;
import network.loki.messenger.libsession_util.UserProfile;
/**
* Will be called once when the TextSecure process is created.
@ -203,6 +204,9 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
@Override
public void notifyUpdates(@NonNull ConfigBase forConfigObject) {
// forward to the config factory / storage ig
if (forConfigObject instanceof UserProfile && !textSecurePreferences.getConfigurationMessageSynced()) {
textSecurePreferences.setConfigurationMessageSynced(true);
}
storage.notifyConfigUpdates(forConfigObject);
}
@Override

View File

@ -2,10 +2,12 @@ package org.thoughtcrime.securesms.database
import android.content.ContentValues
import android.content.Context
import androidx.core.database.getStringOrNull
import android.database.Cursor
import androidx.core.database.getStringOrNull
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.utilities.SessionId
import org.session.libsignal.utilities.Base64
import org.session.libsignal.utilities.IdPrefix
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
@ -43,6 +45,9 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
val database = databaseHelper.readableDatabase
return database.getAll(sessionContactTable, null, null) { cursor ->
contactFromCursor(cursor)
}.filter { contact ->
val sessionId = SessionId(contact.sessionID)
sessionId.prefix == IdPrefix.STANDARD
}.toSet()
}

View File

@ -8,6 +8,7 @@ import network.loki.messenger.libsession_util.UserProfile
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.ConfigFactoryUpdateListener
import org.session.libsignal.protos.SignalServiceProtos.SharedConfigMessage
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.database.ConfigDatabase
import java.util.concurrent.ConcurrentSkipListSet
@ -39,9 +40,11 @@ class ConfigFactory(private val context: Context,
fun registerListener(listener: ConfigFactoryUpdateListener) { listeners += listener }
fun unregisterListener(listener: ConfigFactoryUpdateListener) { listeners -= listener }
override val user: UserProfile? = synchronized(userLock) {
override val user: UserProfile? get() = synchronized(userLock) {
if (_userConfig == null) {
Log.d("Loki-DBG", "Getting user info")
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
Log.d("Loki-DBG", "Getting user configs and hashes")
val userDump = configDatabase.retrieveConfigAndHashes(SharedConfigMessage.Kind.USER_PROFILE.name, publicKey)
_userConfig = if (userDump != null) {
val (bytes, hashes) = userDump
@ -55,7 +58,7 @@ class ConfigFactory(private val context: Context,
_userConfig
}
override val contacts: Contacts? = synchronized(contactsLock) {
override val contacts: Contacts? get() = synchronized(contactsLock) {
if (_contacts == null) {
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
val contactsDump = configDatabase.retrieveConfigAndHashes(SharedConfigMessage.Kind.CONTACTS.name, publicKey)
@ -71,7 +74,7 @@ class ConfigFactory(private val context: Context,
_contacts
}
override val convoVolatile: ConversationVolatileConfig? = synchronized(convoVolatileLock) {
override val convoVolatile: ConversationVolatileConfig? get() = synchronized(convoVolatileLock) {
if (_convoVolatileConfig == null) {
val (secretKey, publicKey) = maybeGetUserInfo() ?: return@synchronized null
val convoDump = configDatabase.retrieveConfigAndHashes(SharedConfigMessage.Kind.CONVO_INFO_VOLATILE.name, publicKey)

View File

@ -133,9 +133,8 @@ class LinkDeviceActivity : BaseActionBarActivity(), ScanQRCodeWrapperFragmentDel
.setAction(R.string.registration_activity__skip) { register(true) }
val skipJob = launch {
delay(30_000L)
delay(15_000L)
snackBar.show()
// show a dialog or something saying do you want to skip this bit?
}
// start polling and wait for updated message
ApplicationContext.getInstance(this@LinkDeviceActivity).apply {

View File

@ -187,6 +187,12 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
requestSparseArray[request.namespace!!] = request
}
if (requestSparseArray.size() == 1) {
// only one (the personal messages)
Log.d("Loki-DBG", "Not building requests for the configs, current config state:")
Log.d("Loki-DBG", "${listOf(configFactory.user, configFactory.contacts, configFactory.convoVolatile)}")
}
val requests = requestSparseArray.valueIterator().asSequence().toList()
SnodeAPI.getRawBatchResponse(snode, userPublicKey, requests).bind { rawResponses ->