Fix order of check to get notification status
This commit is contained in:
parent
ac05e757be
commit
e9daef97b6
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user