Skip to content

Commit b0ccac3

Browse files
committed
Fixes crash on start up
1 parent d2e2ce4 commit b0ccac3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

app/src/main/java/org/thoughtcrime/securesms/configs/ConfigToDatabaseSync.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import android.content.Context
44
import dagger.hilt.android.qualifiers.ApplicationContext
55
import kotlinx.coroutines.CoroutineScope
66
import kotlinx.coroutines.Dispatchers
7+
import kotlinx.coroutines.ExperimentalCoroutinesApi
78
import kotlinx.coroutines.flow.collectLatest
89
import kotlinx.coroutines.flow.distinctUntilChanged
910
import kotlinx.coroutines.flow.filterNotNull
1011
import kotlinx.coroutines.flow.first
12+
import kotlinx.coroutines.flow.flatMapLatest
1113
import kotlinx.coroutines.flow.map
1214
import kotlinx.coroutines.flow.onStart
15+
import kotlinx.coroutines.flow.take
1316
import kotlinx.coroutines.launch
1417
import network.loki.messenger.R
1518
import network.loki.messenger.libsession_util.ReadableGroupInfoConfig
@@ -57,6 +60,7 @@ private const val TAG = "ConfigToDatabaseSync"
5760
*
5861
* @see ConfigUploader For upload config system data into swarm automagically.
5962
*/
63+
@OptIn(ExperimentalCoroutinesApi::class)
6064
class ConfigToDatabaseSync @Inject constructor(
6165
@param:ApplicationContext private val context: Context,
6266
private val configFactory: ConfigFactoryProtocol,
@@ -80,7 +84,10 @@ class ConfigToDatabaseSync @Inject constructor(
8084
init {
8185
// Sync conversations from config -> database
8286
scope.launch {
83-
conversationRepository.conversationListAddressesFlow
87+
preferences.watchLocalNumber()
88+
.filterNotNull()
89+
.take(1)
90+
.flatMapLatest { conversationRepository.conversationListAddressesFlow }
8491
.map { addresses ->
8592
addresses to configFactory.withUserConfigs { it.convoInfoVolatile.all() }
8693
}

app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class DefaultConversationRepository @Inject constructor(
163163
.stateIn(scope, SharingStarted.Eagerly, getConversationListAddresses())
164164

165165
private fun getConversationListAddresses() = buildSet {
166-
val myAddress = Address.Standard(AccountId(textSecurePreferences.getLocalNumber()!!))
166+
val myAddress = Address.Standard(AccountId(textSecurePreferences.getLocalNumber() ?: return@buildSet ))
167167

168168
configFactory.withUserConfigs { configs ->
169169
// Have NTS?

0 commit comments

Comments
 (0)