Skip to content

Commit e9daef9

Browse files
author
Maxime NATUREL
committed
Fix order of check to get notification status
1 parent ac05e75 commit e9daef9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

vector/src/main/java/im/vector/app/features/settings/devices/v2/notification/GetNotificationsStatusUseCase.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ class GetNotificationsStatusUseCase @Inject constructor(
3838
val session = activeSessionHolder.getSafeActiveSession()
3939
return when {
4040
session == null -> flowOf(NotificationsStatus.NOT_SUPPORTED)
41-
checkIfCanTogglePushNotificationsViaPusherUseCase.execute() -> {
42-
session.flow()
43-
.livePushers()
44-
.map { it.filter { pusher -> pusher.deviceId == deviceId } }
45-
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } }
46-
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
47-
.distinctUntilChanged()
48-
}
4941
checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(deviceId) -> {
5042
session.flow()
5143
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
@@ -54,6 +46,14 @@ class GetNotificationsStatusUseCase @Inject constructor(
5446
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
5547
.distinctUntilChanged()
5648
}
49+
checkIfCanTogglePushNotificationsViaPusherUseCase.execute() -> {
50+
session.flow()
51+
.livePushers()
52+
.map { it.filter { pusher -> pusher.deviceId == deviceId } }
53+
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } }
54+
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
55+
.distinctUntilChanged()
56+
}
5757
else -> flowOf(NotificationsStatus.NOT_SUPPORTED)
5858
}
5959
}

vector/src/test/java/im/vector/app/features/settings/devices/v2/notification/GetNotificationsStatusUseCaseTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import im.vector.app.test.fixtures.PusherFixture
2222
import im.vector.app.test.testDispatcher
2323
import io.mockk.every
2424
import io.mockk.mockk
25+
import io.mockk.verifyOrder
2526
import kotlinx.coroutines.Dispatchers
2627
import kotlinx.coroutines.flow.firstOrNull
2728
import kotlinx.coroutines.test.resetMain
@@ -89,6 +90,11 @@ class GetNotificationsStatusUseCaseTest {
8990

9091
// Then
9192
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
93+
verifyOrder {
94+
// we should first check account data
95+
fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(A_DEVICE_ID)
96+
fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute()
97+
}
9298
}
9399

94100
@Test

0 commit comments

Comments
 (0)