mirror of
https://github.com/oxen-io/session-android.git
synced 2025-03-01 14:47:25 +00:00
Merge pull request #1508 from simophin/fix-home-screen-dispatcher
Correct the usage of flowOn
This commit is contained in:
commit
01655b8633
@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.home
|
|||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.asFlow
|
import androidx.lifecycle.asFlow
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
@ -22,7 +21,6 @@ import kotlinx.coroutines.flow.flowOn
|
|||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.mapLatest
|
import kotlinx.coroutines.flow.mapLatest
|
||||||
import kotlinx.coroutines.flow.merge
|
import kotlinx.coroutines.flow.merge
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
@ -60,12 +58,10 @@ class HomeViewModel @Inject constructor(
|
|||||||
observeTypingStatus(),
|
observeTypingStatus(),
|
||||||
messageRequests(),
|
messageRequests(),
|
||||||
::Data
|
::Data
|
||||||
)
|
).stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
||||||
.stateIn(viewModelScope, SharingStarted.Eagerly, null)
|
|
||||||
|
|
||||||
private fun hasHiddenMessageRequests() = TextSecurePreferences.events
|
private fun hasHiddenMessageRequests() = TextSecurePreferences.events
|
||||||
.filter { it == TextSecurePreferences.HAS_HIDDEN_MESSAGE_REQUESTS }
|
.filter { it == TextSecurePreferences.HAS_HIDDEN_MESSAGE_REQUESTS }
|
||||||
.flowOn(Dispatchers.IO)
|
|
||||||
.map { prefs.hasHiddenMessageRequests() }
|
.map { prefs.hasHiddenMessageRequests() }
|
||||||
.onStart { emit(prefs.hasHiddenMessageRequests()) }
|
.onStart { emit(prefs.hasHiddenMessageRequests()) }
|
||||||
|
|
||||||
@ -81,7 +77,7 @@ class HomeViewModel @Inject constructor(
|
|||||||
hasHiddenMessageRequests(),
|
hasHiddenMessageRequests(),
|
||||||
latestUnapprovedConversationTimestamp(),
|
latestUnapprovedConversationTimestamp(),
|
||||||
::createMessageRequests
|
::createMessageRequests
|
||||||
)
|
).flowOn(Dispatchers.IO)
|
||||||
|
|
||||||
private fun unapprovedConversationCount() = reloadTriggersAndContentChanges()
|
private fun unapprovedConversationCount() = reloadTriggersAndContentChanges()
|
||||||
.map { threadDb.unapprovedConversationCount }
|
.map { threadDb.unapprovedConversationCount }
|
||||||
@ -96,13 +92,13 @@ class HomeViewModel @Inject constructor(
|
|||||||
threadDb.readerFor(openCursor).run { generateSequence { next }.toList() }
|
threadDb.readerFor(openCursor).run { generateSequence { next }.toList() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.flowOn(Dispatchers.IO)
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
private fun reloadTriggersAndContentChanges() = merge(
|
private fun reloadTriggersAndContentChanges() = merge(
|
||||||
manualReloadTrigger,
|
manualReloadTrigger,
|
||||||
contentResolver.observeChanges(DatabaseContentProviders.ConversationList.CONTENT_URI)
|
contentResolver.observeChanges(DatabaseContentProviders.ConversationList.CONTENT_URI)
|
||||||
)
|
)
|
||||||
.flowOn(Dispatchers.IO)
|
|
||||||
.debounce(CHANGE_NOTIFICATION_DEBOUNCE_MILLS)
|
.debounce(CHANGE_NOTIFICATION_DEBOUNCE_MILLS)
|
||||||
.onStart { emit(Unit) }
|
.onStart { emit(Unit) }
|
||||||
|
|
||||||
@ -114,7 +110,7 @@ class HomeViewModel @Inject constructor(
|
|||||||
val messageRequests: MessageRequests? = null
|
val messageRequests: MessageRequests? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createMessageRequests(
|
private fun createMessageRequests(
|
||||||
count: Int,
|
count: Int,
|
||||||
hidden: Boolean,
|
hidden: Boolean,
|
||||||
timestamp: Long
|
timestamp: Long
|
||||||
|
Loading…
x
Reference in New Issue
Block a user