diff --git a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java index be077b8d47..dea2071d12 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java +++ b/app/src/main/java/org/thoughtcrime/securesms/ApplicationContext.java @@ -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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SessionContactDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/SessionContactDatabase.kt index 40eee97428..49a6339368 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SessionContactDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SessionContactDatabase.kt @@ -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() } 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 055e00b35f..bef2e01a5f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ConfigFactory.kt @@ -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) diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt index 5dc3f0d52f..edd1bc274a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt @@ -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 { diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index bde22a5dac..bd1b1afaea 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -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 ->