diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeViewModel.kt index fa18a995b6..6819054b31 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeViewModel.kt @@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.home import android.content.ContentResolver import android.content.Context -import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.asFlow import androidx.lifecycle.viewModelScope @@ -22,9 +21,9 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.merge -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.withContext import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.database.DatabaseContentProviders @@ -60,12 +59,10 @@ class HomeViewModel @Inject constructor( observeTypingStatus(), messageRequests(), ::Data - ) - .stateIn(viewModelScope, SharingStarted.Eagerly, null) + ).stateIn(viewModelScope, SharingStarted.Eagerly, null) private fun hasHiddenMessageRequests() = TextSecurePreferences.events .filter { it == TextSecurePreferences.HAS_HIDDEN_MESSAGE_REQUESTS } - .flowOn(Dispatchers.IO) .map { prefs.hasHiddenMessageRequests() } .onStart { emit(prefs.hasHiddenMessageRequests()) } @@ -81,7 +78,7 @@ class HomeViewModel @Inject constructor( hasHiddenMessageRequests(), latestUnapprovedConversationTimestamp(), ::createMessageRequests - ) + ).flowOn(Dispatchers.IO) private fun unapprovedConversationCount() = reloadTriggersAndContentChanges() .map { threadDb.unapprovedConversationCount } @@ -96,13 +93,13 @@ class HomeViewModel @Inject constructor( threadDb.readerFor(openCursor).run { generateSequence { next }.toList() } } } + .flowOn(Dispatchers.IO) @OptIn(FlowPreview::class) private fun reloadTriggersAndContentChanges() = merge( manualReloadTrigger, contentResolver.observeChanges(DatabaseContentProviders.ConversationList.CONTENT_URI) ) - .flowOn(Dispatchers.IO) .debounce(CHANGE_NOTIFICATION_DEBOUNCE_MILLS) .onStart { emit(Unit) } @@ -114,7 +111,7 @@ class HomeViewModel @Inject constructor( val messageRequests: MessageRequests? = null ) - fun createMessageRequests( + private fun createMessageRequests( count: Int, hidden: Boolean, timestamp: Long