Skip to content

Commit ac05e75

Browse files
author
Maxime NATUREL
committed
Small improvement to avoid tou many viewState updates
1 parent 52a77e0 commit ac05e75

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package im.vector.app.features.settings.devices.v2.notification
1818

1919
import im.vector.app.core.di.ActiveSessionHolder
2020
import kotlinx.coroutines.flow.Flow
21+
import kotlinx.coroutines.flow.distinctUntilChanged
2122
import kotlinx.coroutines.flow.flowOf
2223
import kotlinx.coroutines.flow.map
2324
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
@@ -43,13 +44,15 @@ class GetNotificationsStatusUseCase @Inject constructor(
4344
.map { it.filter { pusher -> pusher.deviceId == deviceId } }
4445
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } }
4546
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
47+
.distinctUntilChanged()
4648
}
4749
checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(deviceId) -> {
4850
session.flow()
4951
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
5052
.unwrap()
5153
.map { it.content.toModel<LocalNotificationSettingsContent>()?.isSilenced?.not() }
5254
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
55+
.distinctUntilChanged()
5356
}
5457
else -> flowOf(NotificationsStatus.NOT_SUPPORTED)
5558
}

vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import im.vector.app.features.auth.PendingAuthHandler
3030
import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase
3131
import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel
3232
import im.vector.app.features.settings.devices.v2.notification.GetNotificationsStatusUseCase
33-
import im.vector.app.features.settings.devices.v2.notification.NotificationsStatus
3433
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
3534
import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase
3635
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionResult
@@ -220,9 +219,6 @@ class SessionOverviewViewModel @AssistedInject constructor(
220219
private fun handleTogglePusherAction(action: SessionOverviewAction.TogglePushNotifications) {
221220
viewModelScope.launch {
222221
togglePushNotificationUseCase.execute(action.deviceId, action.enabled)
223-
// TODO should not be needed => test without
224-
val status = if (action.enabled) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED
225-
setState { copy(notificationsStatus = status) }
226222
}
227223
}
228224
}

0 commit comments

Comments
 (0)