diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt index 6de4b586c0..cad8ef8287 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsController.kt @@ -41,11 +41,11 @@ class RoomNotificationSettingsController @Inject constructor() : TypedEpoxyContr } @StringRes - private fun titleForNotificationState(notificationState: RoomNotificationState) = when(notificationState) { - RoomNotificationState.ALL_MESSAGES_NOISY -> R.string.room_settings_all_messages_noisy - RoomNotificationState.ALL_MESSAGES -> R.string.room_settings_all_messages - RoomNotificationState.MENTIONS_ONLY -> R.string.room_settings_mention_only - RoomNotificationState.MUTE -> R.string.room_settings_mute + private fun titleForNotificationState(notificationState: RoomNotificationState): Int? = when(notificationState) { + RoomNotificationState.ALL_MESSAGES_NOISY -> R.string.room_settings_all_messages + RoomNotificationState.MENTIONS_ONLY -> R.string.room_settings_mention_and_keyword_only + RoomNotificationState.MUTE -> R.string.room_settings_none + else -> null } override fun buildModels(data: RoomNotificationSettingsViewState?) { @@ -61,7 +61,7 @@ class RoomNotificationSettingsController @Inject constructor() : TypedEpoxyContr radioButtonItem { id(notificationState.name) titleRes(title) - selected(data.notificationState() == notificationState) + selected(data.notificationStateMapped() == notificationState) listener { host.callback?.didSelectRoomNotificationState(notificationState) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt index 2f1916751f..bff1a26595 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/notifications/RoomNotificationSettingsViewState.kt @@ -18,6 +18,7 @@ package im.vector.app.features.roomprofile.notifications import com.airbnb.mvrx.Async import com.airbnb.mvrx.MvRxState +import com.airbnb.mvrx.Success import com.airbnb.mvrx.Uninitialized import im.vector.app.features.roomprofile.RoomProfileArgs import org.matrix.android.sdk.api.session.room.model.RoomSummary @@ -30,7 +31,6 @@ data class RoomNotificationSettingsViewState( val roomEncrypted: Boolean = false, val notificationState: Async = Uninitialized, ) : MvRxState { - constructor(args: RoomProfileArgs) : this(roomId = args.roomId) } @@ -39,10 +39,26 @@ data class AvatarData ( val avatarUrl: String ) +/** + * Used to map this old room notification settings to the new options in v2. + */ +val RoomNotificationSettingsViewState.notificationStateMapped: Async + get() { + if ((roomEncrypted && notificationState() == RoomNotificationState.MENTIONS_ONLY) || notificationState() == RoomNotificationState.ALL_MESSAGES) { + /** if in an encrypted room, mentions notifications are not supported so show "All Messages" as selected. + * Also in the new settings there is no notion of notifications without sound so it maps to noisy also + */ + return Success(RoomNotificationState.ALL_MESSAGES_NOISY) + } + return notificationState + } +/** + * Used to enumerate the new settings in notification settings v2. Notifications without sound and mentions in encrypted rooms not supported. + */ val RoomNotificationSettingsViewState.notificationOptions: List get() { return if (roomEncrypted) { - listOf(RoomNotificationState.ALL_MESSAGES_NOISY, RoomNotificationState.ALL_MESSAGES, RoomNotificationState.MUTE) + listOf(RoomNotificationState.ALL_MESSAGES_NOISY, RoomNotificationState.MUTE) } else - RoomNotificationState.values().asList() + listOf(RoomNotificationState.ALL_MESSAGES_NOISY, RoomNotificationState.MENTIONS_ONLY, RoomNotificationState.MUTE) } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 5cf121b388..05980c8914 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1037,6 +1037,8 @@ All messages Mentions only Mute + Mentions & Keywords only + None Favourite De-prioritize Direct Chat