mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Small improvement to avoid tou many viewState updates
This commit is contained in:
parent
52a77e074f
commit
ac05e757be
2 changed files with 3 additions and 4 deletions
|
@ -18,6 +18,7 @@ package im.vector.app.features.settings.devices.v2.notification
|
|||
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||
|
@ -43,6 +44,7 @@ class GetNotificationsStatusUseCase @Inject constructor(
|
|||
.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()
|
||||
|
@ -50,6 +52,7 @@ class GetNotificationsStatusUseCase @Inject constructor(
|
|||
.unwrap()
|
||||
.map { it.content.toModel<LocalNotificationSettingsContent>()?.isSilenced?.not() }
|
||||
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
|
||||
.distinctUntilChanged()
|
||||
}
|
||||
else -> flowOf(NotificationsStatus.NOT_SUPPORTED)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import im.vector.app.features.auth.PendingAuthHandler
|
|||
import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase
|
||||
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.NotificationsStatus
|
||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
||||
import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase
|
||||
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionResult
|
||||
|
@ -220,9 +219,6 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
|||
private fun handleTogglePusherAction(action: SessionOverviewAction.TogglePushNotifications) {
|
||||
viewModelScope.launch {
|
||||
togglePushNotificationUseCase.execute(action.deviceId, action.enabled)
|
||||
// TODO should not be needed => test without
|
||||
val status = if (action.enabled) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED
|
||||
setState { copy(notificationsStatus = status) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue