initialisating channels as part of the first notification emission rather than blocking application init

This commit is contained in:
Adam Brown 2022-07-13 18:32:10 +01:00
parent 6f18d48905
commit 63618276b7
2 changed files with 9 additions and 6 deletions

View File

@ -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()
}

View File

@ -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()
}