mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-18 04:08:44 +03:00
Fix order of check to get notification status
This commit is contained in:
parent
ac05e757be
commit
e9daef97b6
2 changed files with 14 additions and 8 deletions
|
@ -38,14 +38,6 @@ class GetNotificationsStatusUseCase @Inject constructor(
|
|||
val session = activeSessionHolder.getSafeActiveSession()
|
||||
return when {
|
||||
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) -> {
|
||||
session.flow()
|
||||
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
|
||||
|
@ -54,6 +46,14 @@ class GetNotificationsStatusUseCase @Inject constructor(
|
|||
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
|
||||
.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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import im.vector.app.test.fixtures.PusherFixture
|
|||
import im.vector.app.test.testDispatcher
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verifyOrder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
|
@ -89,6 +90,11 @@ class GetNotificationsStatusUseCaseTest {
|
|||
|
||||
// Then
|
||||
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
|
||||
verifyOrder {
|
||||
// we should first check account data
|
||||
fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(A_DEVICE_ID)
|
||||
fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Reference in a new issue