Fix order of check to get notification status

This commit is contained in:
Maxime NATUREL 2022-11-03 11:27:02 +01:00
parent ac05e757be
commit e9daef97b6
2 changed files with 14 additions and 8 deletions

View File

@ -38,14 +38,6 @@ class GetNotificationsStatusUseCase @Inject constructor(
val session = activeSessionHolder.getSafeActiveSession() val session = activeSessionHolder.getSafeActiveSession()
return when { return when {
session == null -> flowOf(NotificationsStatus.NOT_SUPPORTED) session == null -> flowOf(NotificationsStatus.NOT_SUPPORTED)
checkIfCanTogglePushNotificationsViaPusherUseCase.execute() -> {
session.flow()
.livePushers()
.map { it.filter { pusher -> pusher.deviceId == deviceId } }
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } }
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
.distinctUntilChanged()
}
checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(deviceId) -> { checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(deviceId) -> {
session.flow() session.flow()
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId) .liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
@ -54,6 +46,14 @@ class GetNotificationsStatusUseCase @Inject constructor(
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED } .map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
.distinctUntilChanged() .distinctUntilChanged()
} }
checkIfCanTogglePushNotificationsViaPusherUseCase.execute() -> {
session.flow()
.livePushers()
.map { it.filter { pusher -> pusher.deviceId == deviceId } }
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } }
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
.distinctUntilChanged()
}
else -> flowOf(NotificationsStatus.NOT_SUPPORTED) else -> flowOf(NotificationsStatus.NOT_SUPPORTED)
} }
} }

View File

@ -22,6 +22,7 @@ import im.vector.app.test.fixtures.PusherFixture
import im.vector.app.test.testDispatcher import im.vector.app.test.testDispatcher
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verifyOrder
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.resetMain
@ -89,6 +90,11 @@ class GetNotificationsStatusUseCaseTest {
// Then // Then
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
verifyOrder {
// we should first check account data
fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(A_DEVICE_ID)
fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute()
}
} }
@Test @Test