mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 09:55:40 +03:00
Renaming some use cases to be consistent
This commit is contained in:
parent
14b21dc039
commit
7c51174d7e
16 changed files with 85 additions and 84 deletions
|
@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.flow.unwrap
|
import org.matrix.android.sdk.flow.unwrap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CanTogglePushNotificationsViaPusherUseCase @Inject constructor() {
|
class CanToggleNotificationsViaPusherUseCase @Inject constructor() {
|
||||||
|
|
||||||
fun execute(session: Session): Flow<Boolean> {
|
fun execute(session: Session): Flow<Boolean> {
|
||||||
return session
|
return session
|
|
@ -22,7 +22,7 @@ import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CheckIfCanTogglePushNotificationsViaAccountDataUseCase @Inject constructor() {
|
class CheckIfCanToggleNotificationsViaAccountDataUseCase @Inject constructor() {
|
||||||
|
|
||||||
fun execute(session: Session, deviceId: String): Boolean {
|
fun execute(session: Session, deviceId: String): Boolean {
|
||||||
return session
|
return session
|
|
@ -19,7 +19,7 @@ package im.vector.app.features.settings.devices.v2.notification
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CheckIfCanTogglePushNotificationsViaPusherUseCase @Inject constructor() {
|
class CheckIfCanToggleNotificationsViaPusherUseCase @Inject constructor() {
|
||||||
|
|
||||||
fun execute(session: Session): Boolean {
|
fun execute(session: Session): Boolean {
|
||||||
return session
|
return session
|
|
@ -30,13 +30,13 @@ import org.matrix.android.sdk.flow.unwrap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class GetNotificationsStatusUseCase @Inject constructor(
|
class GetNotificationsStatusUseCase @Inject constructor(
|
||||||
private val canTogglePushNotificationsViaPusherUseCase: CanTogglePushNotificationsViaPusherUseCase,
|
private val canToggleNotificationsViaPusherUseCase: CanToggleNotificationsViaPusherUseCase,
|
||||||
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase: CheckIfCanTogglePushNotificationsViaAccountDataUseCase,
|
private val checkIfCanToggleNotificationsViaAccountDataUseCase: CheckIfCanToggleNotificationsViaAccountDataUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun execute(session: Session, deviceId: String): Flow<NotificationsStatus> {
|
fun execute(session: Session, deviceId: String): Flow<NotificationsStatus> {
|
||||||
return when {
|
return when {
|
||||||
checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(session, deviceId) -> {
|
checkIfCanToggleNotificationsViaAccountDataUseCase.execute(session, deviceId) -> {
|
||||||
session.flow()
|
session.flow()
|
||||||
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
|
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -44,7 +44,7 @@ class GetNotificationsStatusUseCase @Inject constructor(
|
||||||
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
|
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
else -> canTogglePushNotificationsViaPusherUseCase.execute(session)
|
else -> canToggleNotificationsViaPusherUseCase.execute(session)
|
||||||
.flatMapLatest { canToggle ->
|
.flatMapLatest { canToggle ->
|
||||||
if (canToggle) {
|
if (canToggle) {
|
||||||
session.flow()
|
session.flow()
|
||||||
|
|
|
@ -20,25 +20,24 @@ import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
// TODO rename into ToggleNotificationsUseCase
|
class ToggleNotificationUseCase @Inject constructor(
|
||||||
class TogglePushNotificationUseCase @Inject constructor(
|
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
|
private val checkIfCanToggleNotificationsViaPusherUseCase: CheckIfCanToggleNotificationsViaPusherUseCase,
|
||||||
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase: CheckIfCanTogglePushNotificationsViaAccountDataUseCase,
|
private val checkIfCanToggleNotificationsViaAccountDataUseCase: CheckIfCanToggleNotificationsViaAccountDataUseCase,
|
||||||
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase,
|
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun execute(deviceId: String, enabled: Boolean) {
|
suspend fun execute(deviceId: String, enabled: Boolean) {
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
|
|
||||||
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
|
if (checkIfCanToggleNotificationsViaPusherUseCase.execute(session)) {
|
||||||
val devicePusher = session.pushersService().getPushers().firstOrNull { it.deviceId == deviceId }
|
val devicePusher = session.pushersService().getPushers().firstOrNull { it.deviceId == deviceId }
|
||||||
devicePusher?.let { pusher ->
|
devicePusher?.let { pusher ->
|
||||||
session.pushersService().togglePusher(pusher, enabled)
|
session.pushersService().togglePusher(pusher, enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(session, deviceId)) {
|
if (checkIfCanToggleNotificationsViaAccountDataUseCase.execute(session, deviceId)) {
|
||||||
val newNotificationSettingsContent = LocalNotificationSettingsContent(isSilenced = !enabled)
|
val newNotificationSettingsContent = LocalNotificationSettingsContent(isSilenced = !enabled)
|
||||||
setNotificationSettingsAccountDataUseCase.execute(deviceId, newNotificationSettingsContent)
|
setNotificationSettingsAccountDataUseCase.execute(deviceId, newNotificationSettingsContent)
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase
|
import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel
|
import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel
|
||||||
import im.vector.app.features.settings.devices.v2.notification.GetNotificationsStatusUseCase
|
import im.vector.app.features.settings.devices.v2.notification.GetNotificationsStatusUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase
|
import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsReAuthNeeded
|
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsReAuthNeeded
|
||||||
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsUseCase
|
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsUseCase
|
||||||
|
@ -54,7 +54,7 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
||||||
private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase,
|
private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase,
|
||||||
private val pendingAuthHandler: PendingAuthHandler,
|
private val pendingAuthHandler: PendingAuthHandler,
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
|
private val toggleNotificationUseCase: ToggleNotificationUseCase,
|
||||||
private val getNotificationsStatusUseCase: GetNotificationsStatusUseCase,
|
private val getNotificationsStatusUseCase: GetNotificationsStatusUseCase,
|
||||||
refreshDevicesUseCase: RefreshDevicesUseCase,
|
refreshDevicesUseCase: RefreshDevicesUseCase,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
|
@ -228,7 +228,7 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
private fun handleTogglePusherAction(action: SessionOverviewAction.TogglePushNotifications) {
|
private fun handleTogglePusherAction(action: SessionOverviewAction.TogglePushNotifications) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
togglePushNotificationUseCase.execute(action.deviceId, action.enabled)
|
toggleNotificationUseCase.execute(action.deviceId, action.enabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,23 +19,23 @@ package im.vector.app.features.settings.notifications
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanTogglePushNotificationsViaPusherUseCase
|
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanToggleNotificationsViaPusherUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
|
class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val pushersManager: PushersManager,
|
private val pushersManager: PushersManager,
|
||||||
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
|
private val checkIfCanToggleNotificationsViaPusherUseCase: CheckIfCanToggleNotificationsViaPusherUseCase,
|
||||||
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
|
private val toggleNotificationUseCase: ToggleNotificationUseCase,
|
||||||
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
|
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun execute() {
|
suspend fun execute() {
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
val deviceId = session.sessionParams.deviceId ?: return
|
val deviceId = session.sessionParams.deviceId ?: return
|
||||||
togglePushNotificationUseCase.execute(deviceId, enabled = false)
|
toggleNotificationUseCase.execute(deviceId, enabled = false)
|
||||||
if (!checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
|
if (!checkIfCanToggleNotificationsViaPusherUseCase.execute(session)) {
|
||||||
unregisterUnifiedPushUseCase.execute(pushersManager)
|
unregisterUnifiedPushUseCase.execute(pushersManager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,13 @@ import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
|
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
|
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class EnableNotificationsForCurrentSessionUseCase @Inject constructor(
|
class EnableNotificationsForCurrentSessionUseCase @Inject constructor(
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val pushersManager: PushersManager,
|
private val pushersManager: PushersManager,
|
||||||
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
|
private val toggleNotificationUseCase: ToggleNotificationUseCase,
|
||||||
private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase,
|
private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase,
|
||||||
private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase,
|
private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase,
|
||||||
) {
|
) {
|
||||||
|
@ -52,7 +52,7 @@ class EnableNotificationsForCurrentSessionUseCase @Inject constructor(
|
||||||
|
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return EnableNotificationsResult.Failure
|
val session = activeSessionHolder.getSafeActiveSession() ?: return EnableNotificationsResult.Failure
|
||||||
val deviceId = session.sessionParams.deviceId ?: return EnableNotificationsResult.Failure
|
val deviceId = session.sessionParams.deviceId ?: return EnableNotificationsResult.Failure
|
||||||
togglePushNotificationUseCase.execute(deviceId, enabled = true)
|
toggleNotificationUseCase.execute(deviceId, enabled = true)
|
||||||
|
|
||||||
return EnableNotificationsResult.Success
|
return EnableNotificationsResult.Success
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ import org.junit.Test
|
||||||
|
|
||||||
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canRemotelyTogglePushNotificationsOfDevices = true)
|
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canRemotelyTogglePushNotificationsOfDevices = true)
|
||||||
|
|
||||||
class CanTogglePushNotificationsViaPusherUseCaseTest {
|
class CanToggleNotificationsViaPusherUseCaseTest {
|
||||||
|
|
||||||
private val fakeSession = FakeSession()
|
private val fakeSession = FakeSession()
|
||||||
private val fakeFlowLiveDataConversions = FakeFlowLiveDataConversions()
|
private val fakeFlowLiveDataConversions = FakeFlowLiveDataConversions()
|
||||||
|
|
||||||
private val canTogglePushNotificationsViaPusherUseCase =
|
private val canToggleNotificationsViaPusherUseCase =
|
||||||
CanTogglePushNotificationsViaPusherUseCase()
|
CanToggleNotificationsViaPusherUseCase()
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
|
@ -57,7 +57,7 @@ class CanTogglePushNotificationsViaPusherUseCaseTest {
|
||||||
.givenAsFlow()
|
.givenAsFlow()
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = canTogglePushNotificationsViaPusherUseCase.execute(fakeSession).firstOrNull()
|
val result = canToggleNotificationsViaPusherUseCase.execute(fakeSession).firstOrNull()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result shouldBeEqualTo A_HOMESERVER_CAPABILITIES.canRemotelyTogglePushNotificationsOfDevices
|
result shouldBeEqualTo A_HOMESERVER_CAPABILITIES.canRemotelyTogglePushNotificationsOfDevices
|
|
@ -26,12 +26,12 @@ import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
|
|
||||||
private const val A_DEVICE_ID = "device-id"
|
private const val A_DEVICE_ID = "device-id"
|
||||||
|
|
||||||
class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
|
class CheckIfCanToggleNotificationsViaAccountDataUseCaseTest {
|
||||||
|
|
||||||
private val fakeSession = FakeSession()
|
private val fakeSession = FakeSession()
|
||||||
|
|
||||||
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase =
|
private val checkIfCanToggleNotificationsViaAccountDataUseCase =
|
||||||
CheckIfCanTogglePushNotificationsViaAccountDataUseCase()
|
CheckIfCanToggleNotificationsViaAccountDataUseCase()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given current session and an account data with a content for the device id when execute then result is true`() {
|
fun `given current session and an account data with a content for the device id when execute then result is true`() {
|
||||||
|
@ -44,7 +44,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result shouldBeEqualTo true
|
result shouldBeEqualTo true
|
||||||
|
@ -61,7 +61,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result shouldBeEqualTo false
|
result shouldBeEqualTo false
|
||||||
|
@ -78,7 +78,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result shouldBeEqualTo false
|
result shouldBeEqualTo false
|
|
@ -23,12 +23,12 @@ import org.junit.Test
|
||||||
|
|
||||||
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canRemotelyTogglePushNotificationsOfDevices = true)
|
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canRemotelyTogglePushNotificationsOfDevices = true)
|
||||||
|
|
||||||
class CheckIfCanTogglePushNotificationsViaPusherUseCaseTest {
|
class CheckIfCanToggleNotificationsViaPusherUseCaseTest {
|
||||||
|
|
||||||
private val fakeSession = FakeSession()
|
private val fakeSession = FakeSession()
|
||||||
|
|
||||||
private val checkIfCanTogglePushNotificationsViaPusherUseCase =
|
private val checkIfCanToggleNotificationsViaPusherUseCase =
|
||||||
CheckIfCanTogglePushNotificationsViaPusherUseCase()
|
CheckIfCanToggleNotificationsViaPusherUseCase()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given current session when execute then toggle capability is returned`() {
|
fun `given current session when execute then toggle capability is returned`() {
|
||||||
|
@ -38,7 +38,7 @@ class CheckIfCanTogglePushNotificationsViaPusherUseCaseTest {
|
||||||
.givenCapabilities(A_HOMESERVER_CAPABILITIES)
|
.givenCapabilities(A_HOMESERVER_CAPABILITIES)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession)
|
val result = checkIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
result shouldBeEqualTo A_HOMESERVER_CAPABILITIES.canRemotelyTogglePushNotificationsOfDevices
|
result shouldBeEqualTo A_HOMESERVER_CAPABILITIES.canRemotelyTogglePushNotificationsOfDevices
|
|
@ -46,15 +46,15 @@ class GetNotificationsStatusUseCaseTest {
|
||||||
val instantTaskExecutorRule = InstantTaskExecutorRule()
|
val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||||
|
|
||||||
private val fakeSession = FakeSession()
|
private val fakeSession = FakeSession()
|
||||||
private val fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase =
|
private val fakeCheckIfCanToggleNotificationsViaAccountDataUseCase =
|
||||||
mockk<CheckIfCanTogglePushNotificationsViaAccountDataUseCase>()
|
mockk<CheckIfCanToggleNotificationsViaAccountDataUseCase>()
|
||||||
private val fakeCanTogglePushNotificationsViaPusherUseCase =
|
private val fakeCanToggleNotificationsViaPusherUseCase =
|
||||||
mockk<CanTogglePushNotificationsViaPusherUseCase>()
|
mockk<CanToggleNotificationsViaPusherUseCase>()
|
||||||
|
|
||||||
private val getNotificationsStatusUseCase =
|
private val getNotificationsStatusUseCase =
|
||||||
GetNotificationsStatusUseCase(
|
GetNotificationsStatusUseCase(
|
||||||
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase,
|
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
|
||||||
canTogglePushNotificationsViaPusherUseCase = fakeCanTogglePushNotificationsViaPusherUseCase,
|
canTogglePushNotificationsViaPusherUseCase = fakeCanToggleNotificationsViaPusherUseCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -70,8 +70,8 @@ class GetNotificationsStatusUseCaseTest {
|
||||||
@Test
|
@Test
|
||||||
fun `given current session and toggle is not supported when execute then resulting flow contains NOT_SUPPORTED value`() = runTest {
|
fun `given current session and toggle is not supported when execute then resulting flow contains NOT_SUPPORTED value`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
|
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
|
||||||
every { fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
|
every { fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
@ -80,8 +80,8 @@ class GetNotificationsStatusUseCaseTest {
|
||||||
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
|
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
|
||||||
verifyOrder {
|
verifyOrder {
|
||||||
// we should first check account data
|
// we should first check account data
|
||||||
fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession)
|
fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,8 +95,8 @@ class GetNotificationsStatusUseCaseTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
fakeSession.pushersService().givenPushersLive(pushers)
|
fakeSession.pushersService().givenPushersLive(pushers)
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
|
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
|
||||||
every { fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(true)
|
every { fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(true)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
@ -116,8 +116,8 @@ class GetNotificationsStatusUseCaseTest {
|
||||||
isSilenced = false
|
isSilenced = false
|
||||||
).toContent(),
|
).toContent(),
|
||||||
)
|
)
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns true
|
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns true
|
||||||
every { fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
|
every { fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
|
|
@ -26,21 +26,21 @@ import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
|
|
||||||
class TogglePushNotificationUseCaseTest {
|
class ToggleNotificationUseCaseTest {
|
||||||
|
|
||||||
private val activeSessionHolder = FakeActiveSessionHolder()
|
private val activeSessionHolder = FakeActiveSessionHolder()
|
||||||
private val fakeCheckIfCanTogglePushNotificationsViaPusherUseCase =
|
private val fakeCheckIfCanToggleNotificationsViaPusherUseCase =
|
||||||
mockk<CheckIfCanTogglePushNotificationsViaPusherUseCase>()
|
mockk<CheckIfCanToggleNotificationsViaPusherUseCase>()
|
||||||
private val fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase =
|
private val fakeCheckIfCanToggleNotificationsViaAccountDataUseCase =
|
||||||
mockk<CheckIfCanTogglePushNotificationsViaAccountDataUseCase>()
|
mockk<CheckIfCanToggleNotificationsViaAccountDataUseCase>()
|
||||||
private val fakeSetNotificationSettingsAccountDataUseCase =
|
private val fakeSetNotificationSettingsAccountDataUseCase =
|
||||||
mockk<SetNotificationSettingsAccountDataUseCase>()
|
mockk<SetNotificationSettingsAccountDataUseCase>()
|
||||||
|
|
||||||
private val togglePushNotificationUseCase =
|
private val toggleNotificationUseCase =
|
||||||
TogglePushNotificationUseCase(
|
ToggleNotificationUseCase(
|
||||||
activeSessionHolder = activeSessionHolder.instance,
|
activeSessionHolder = activeSessionHolder.instance,
|
||||||
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanTogglePushNotificationsViaPusherUseCase,
|
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanToggleNotificationsViaPusherUseCase,
|
||||||
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase,
|
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
|
||||||
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
|
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -55,11 +55,11 @@ class TogglePushNotificationUseCaseTest {
|
||||||
val fakeSession = activeSessionHolder.fakeSession
|
val fakeSession = activeSessionHolder.fakeSession
|
||||||
fakeSession.pushersService().givenPushersLive(pushers)
|
fakeSession.pushersService().givenPushersLive(pushers)
|
||||||
fakeSession.pushersService().givenGetPushers(pushers)
|
fakeSession.pushersService().givenGetPushers(pushers)
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns true
|
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns true
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns false
|
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns false
|
||||||
|
|
||||||
// When
|
// When
|
||||||
togglePushNotificationUseCase.execute(sessionId, true)
|
toggleNotificationUseCase.execute(sessionId, true)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
activeSessionHolder.fakeSession.pushersService().verifyTogglePusherCalled(pushers.first(), true)
|
activeSessionHolder.fakeSession.pushersService().verifyTogglePusherCalled(pushers.first(), true)
|
||||||
|
@ -70,15 +70,15 @@ class TogglePushNotificationUseCaseTest {
|
||||||
// Given
|
// Given
|
||||||
val sessionId = "a_session_id"
|
val sessionId = "a_session_id"
|
||||||
val fakeSession = activeSessionHolder.fakeSession
|
val fakeSession = activeSessionHolder.fakeSession
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns false
|
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns false
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns true
|
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns true
|
||||||
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any()) }
|
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any()) }
|
||||||
val expectedLocalNotificationSettingsContent = LocalNotificationSettingsContent(
|
val expectedLocalNotificationSettingsContent = LocalNotificationSettingsContent(
|
||||||
isSilenced = false
|
isSilenced = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
togglePushNotificationUseCase.execute(sessionId, true)
|
toggleNotificationUseCase.execute(sessionId, true)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
coVerify {
|
coVerify {
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package im.vector.app.features.settings.notifications
|
package im.vector.app.features.settings.notifications
|
||||||
|
|
||||||
|
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanToggleNotificationsViaPusherUseCase
|
||||||
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanTogglePushNotificationsViaPusherUseCase
|
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanTogglePushNotificationsViaPusherUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
||||||
|
@ -34,15 +36,15 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
|
||||||
|
|
||||||
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
||||||
private val fakePushersManager = FakePushersManager()
|
private val fakePushersManager = FakePushersManager()
|
||||||
private val fakeCheckIfCanTogglePushNotificationsViaPusherUseCase = mockk<CheckIfCanTogglePushNotificationsViaPusherUseCase>()
|
private val fakeCheckIfCanToggleNotificationsViaPusherUseCase = mockk<CheckIfCanToggleNotificationsViaPusherUseCase>()
|
||||||
private val fakeTogglePushNotificationUseCase = mockk<TogglePushNotificationUseCase>()
|
private val fakeToggleNotificationUseCase = mockk<ToggleNotificationUseCase>()
|
||||||
private val fakeUnregisterUnifiedPushUseCase = mockk<UnregisterUnifiedPushUseCase>()
|
private val fakeUnregisterUnifiedPushUseCase = mockk<UnregisterUnifiedPushUseCase>()
|
||||||
|
|
||||||
private val disableNotificationsForCurrentSessionUseCase = DisableNotificationsForCurrentSessionUseCase(
|
private val disableNotificationsForCurrentSessionUseCase = DisableNotificationsForCurrentSessionUseCase(
|
||||||
activeSessionHolder = fakeActiveSessionHolder.instance,
|
activeSessionHolder = fakeActiveSessionHolder.instance,
|
||||||
pushersManager = fakePushersManager.instance,
|
pushersManager = fakePushersManager.instance,
|
||||||
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanTogglePushNotificationsViaPusherUseCase,
|
checkIfCanToggleNotificationsViaPusherUseCase = fakeCheckIfCanToggleNotificationsViaPusherUseCase,
|
||||||
togglePushNotificationUseCase = fakeTogglePushNotificationUseCase,
|
toggleNotificationUseCase = fakeToggleNotificationUseCase,
|
||||||
unregisterUnifiedPushUseCase = fakeUnregisterUnifiedPushUseCase,
|
unregisterUnifiedPushUseCase = fakeUnregisterUnifiedPushUseCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,14 +53,14 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
|
||||||
// Given
|
// Given
|
||||||
val fakeSession = fakeActiveSessionHolder.fakeSession
|
val fakeSession = fakeActiveSessionHolder.fakeSession
|
||||||
fakeSession.givenSessionId(A_SESSION_ID)
|
fakeSession.givenSessionId(A_SESSION_ID)
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns true
|
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns true
|
||||||
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
|
coJustRun { fakeToggleNotificationUseCase.execute(A_SESSION_ID, any()) }
|
||||||
|
|
||||||
// When
|
// When
|
||||||
disableNotificationsForCurrentSessionUseCase.execute()
|
disableNotificationsForCurrentSessionUseCase.execute()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
coVerify { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, false) }
|
coVerify { fakeToggleNotificationUseCase.execute(A_SESSION_ID, false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -66,8 +68,8 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
|
||||||
// Given
|
// Given
|
||||||
val fakeSession = fakeActiveSessionHolder.fakeSession
|
val fakeSession = fakeActiveSessionHolder.fakeSession
|
||||||
fakeSession.givenSessionId(A_SESSION_ID)
|
fakeSession.givenSessionId(A_SESSION_ID)
|
||||||
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns false
|
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns false
|
||||||
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
|
coJustRun { fakeToggleNotificationUseCase.execute(A_SESSION_ID, any()) }
|
||||||
coJustRun { fakeUnregisterUnifiedPushUseCase.execute(any()) }
|
coJustRun { fakeUnregisterUnifiedPushUseCase.execute(any()) }
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
@ -75,7 +77,7 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
coVerify {
|
coVerify {
|
||||||
fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, false)
|
fakeToggleNotificationUseCase.execute(A_SESSION_ID, false)
|
||||||
fakeUnregisterUnifiedPushUseCase.execute(fakePushersManager.instance)
|
fakeUnregisterUnifiedPushUseCase.execute(fakePushersManager.instance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ package im.vector.app.features.settings.notifications
|
||||||
|
|
||||||
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
|
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
|
||||||
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
|
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||||
import im.vector.app.test.fakes.FakePushersManager
|
import im.vector.app.test.fakes.FakePushersManager
|
||||||
import io.mockk.coJustRun
|
import io.mockk.coJustRun
|
||||||
|
@ -36,14 +36,14 @@ class EnableNotificationsForCurrentSessionUseCaseTest {
|
||||||
|
|
||||||
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
||||||
private val fakePushersManager = FakePushersManager()
|
private val fakePushersManager = FakePushersManager()
|
||||||
private val fakeTogglePushNotificationUseCase = mockk<TogglePushNotificationUseCase>()
|
private val fakeToggleNotificationUseCase = mockk<ToggleNotificationUseCase>()
|
||||||
private val fakeRegisterUnifiedPushUseCase = mockk<RegisterUnifiedPushUseCase>()
|
private val fakeRegisterUnifiedPushUseCase = mockk<RegisterUnifiedPushUseCase>()
|
||||||
private val fakeEnsureFcmTokenIsRetrievedUseCase = mockk<EnsureFcmTokenIsRetrievedUseCase>()
|
private val fakeEnsureFcmTokenIsRetrievedUseCase = mockk<EnsureFcmTokenIsRetrievedUseCase>()
|
||||||
|
|
||||||
private val enableNotificationsForCurrentSessionUseCase = EnableNotificationsForCurrentSessionUseCase(
|
private val enableNotificationsForCurrentSessionUseCase = EnableNotificationsForCurrentSessionUseCase(
|
||||||
activeSessionHolder = fakeActiveSessionHolder.instance,
|
activeSessionHolder = fakeActiveSessionHolder.instance,
|
||||||
pushersManager = fakePushersManager.instance,
|
pushersManager = fakePushersManager.instance,
|
||||||
togglePushNotificationUseCase = fakeTogglePushNotificationUseCase,
|
toggleNotificationUseCase = fakeToggleNotificationUseCase,
|
||||||
registerUnifiedPushUseCase = fakeRegisterUnifiedPushUseCase,
|
registerUnifiedPushUseCase = fakeRegisterUnifiedPushUseCase,
|
||||||
ensureFcmTokenIsRetrievedUseCase = fakeEnsureFcmTokenIsRetrievedUseCase,
|
ensureFcmTokenIsRetrievedUseCase = fakeEnsureFcmTokenIsRetrievedUseCase,
|
||||||
)
|
)
|
||||||
|
@ -57,7 +57,7 @@ class EnableNotificationsForCurrentSessionUseCaseTest {
|
||||||
fakePushersManager.givenGetPusherForCurrentSessionReturns(null)
|
fakePushersManager.givenGetPusherForCurrentSessionReturns(null)
|
||||||
every { fakeRegisterUnifiedPushUseCase.execute(any()) } returns RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.Success
|
every { fakeRegisterUnifiedPushUseCase.execute(any()) } returns RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.Success
|
||||||
justRun { fakeEnsureFcmTokenIsRetrievedUseCase.execute(any(), any()) }
|
justRun { fakeEnsureFcmTokenIsRetrievedUseCase.execute(any(), any()) }
|
||||||
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
|
coJustRun { fakeToggleNotificationUseCase.execute(A_SESSION_ID, any()) }
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = enableNotificationsForCurrentSessionUseCase.execute(aDistributor)
|
val result = enableNotificationsForCurrentSessionUseCase.execute(aDistributor)
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
|
|
||||||
package im.vector.app.test.fakes
|
package im.vector.app.test.fakes
|
||||||
|
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import io.mockk.coJustRun
|
import io.mockk.coJustRun
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
|
|
||||||
class FakeTogglePushNotificationUseCase {
|
class FakeTogglePushNotificationUseCase {
|
||||||
|
|
||||||
val instance = mockk<TogglePushNotificationUseCase> {
|
val instance = mockk<ToggleNotificationUseCase> {
|
||||||
coJustRun { execute(any(), any()) }
|
coJustRun { execute(any(), any()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue