initialisating channels as part of the first notification emission rather than blocking application init
This commit is contained in:
parent
6f18d48905
commit
63618276b7
|
@ -6,19 +6,17 @@ import app.dapk.st.matrix.sync.RoomEvent
|
|||
import app.dapk.st.matrix.sync.RoomOverview
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
|
||||
class RenderNotificationsUseCase(
|
||||
private val notificationRenderer: NotificationRenderer,
|
||||
private val observeRenderableUnreadEventsUseCase: ObserveUnreadNotificationsUseCase,
|
||||
notificationChannels: NotificationChannels,
|
||||
private val notificationChannels: NotificationChannels,
|
||||
) {
|
||||
|
||||
init {
|
||||
notificationChannels.initChannels()
|
||||
}
|
||||
|
||||
suspend fun listenForNotificationChanges() {
|
||||
observeRenderableUnreadEventsUseCase()
|
||||
.onStart { notificationChannels.initChannels() }
|
||||
.onEach { (each, diff) -> renderUnreadChange(each, diff) }
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -25,7 +25,12 @@ class RenderNotificationsUseCaseTest {
|
|||
)
|
||||
|
||||
@Test
|
||||
fun `when creating use case instance, then initiates channels`() {
|
||||
fun `given events, when listening for changes then initiates channels once`() = runTest {
|
||||
fakeNotificationRenderer.instance.expect { it.render(any()) }
|
||||
fakeObserveUnreadNotificationsUseCase.given().emits(AN_UNREAD_NOTIFICATIONS)
|
||||
|
||||
renderNotificationsUseCase.listenForNotificationChanges()
|
||||
|
||||
fakeNotificationChannels.verifyInitiated()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue