Files
element-x-ios/ElementX/Sources/Screens/Settings/NotificationSettingsScreen/NotificationSettingsScreenModels.swift
T
Stefan Ceriu fc8ee9d93d Room list notifications tweaks (#6106)
We decided against changing how unread activity is rendered in the room list, so the experiment and its developer option are no longer needed.
we have also added a notification settings entry for hiding the room list gray dots.
2026-09-25 13:36:33 +03:00

110 lines
3.9 KiB
Swift

//
// Copyright 2025 Element Creations Ltd.
// Copyright 2022-2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
import UIKit
enum NotificationSettingsScreenViewModelAction {
case close
case editDefaultMode(chatType: NotificationSettingsChatType)
}
struct NotificationSettingsScreenViewState: BindableState {
var bindings: NotificationSettingsScreenViewStateBindings
var strings = NotificationSettingsScreenStrings()
let isModallyPresented: Bool
var isUserPermissionGranted: Bool?
var fixingConfigurationMismatch = false
/// Hide calls settings until calls are available in El-X
let showCallsSettings = false
var showSystemNotificationsAlert: Bool {
bindings.enableNotifications && isUserPermissionGranted == false
}
var settings: NotificationSettingsScreenSettings?
var applyingChange = false
var selectedAlertTone: NotificationTone
var availableCustomTones: [NotificationTone]
let customToneSelectionEnabled: Bool
}
struct NotificationSettingsScreenViewStateBindings {
var enableNotifications = false
var roomMentionsEnabled = false
var callsEnabled = false
var invitationsEnabled = false
var showAllRoomListActivity = true
var alertInfo: AlertInfo<NotificationSettingsScreenErrorType>?
var shouldShowAlertSounds = false
var shouldShowCustomAlertTonePicker = false
}
struct NotificationSettingsScreenSettings {
let groupChatsMode: RoomNotificationModeProxy
let directChatsMode: RoomNotificationModeProxy
let roomMentionsEnabled: Bool?
let callsEnabled: Bool?
let invitationsEnabled: Bool?
/// Old clients were having specific settings for encrypted and unencrypted rooms,
/// so it's possible for `group chats` and `direct chats` settings to be inconsistent (e.g. encrypted `direct chats` can have a different mode that unencrypted `direct chats`)
let inconsistentSettings: [NotificationSettingsScreenInvalidSetting]
}
struct NotificationSettingsScreenInvalidSetting: Equatable {
let chatType: NotificationSettingsChatType
let isEncrypted: Bool
}
struct NotificationSettingsScreenStrings {
let changeYourSystemSettings: AttributedString = {
let linkPlaceholder = "{link}"
var text = AttributedString(L10n.screenNotificationSettingsSystemNotificationsActionRequired(linkPlaceholder))
var linkString = AttributedString(L10n.screenNotificationSettingsSystemNotificationsActionRequiredContentLink)
// Note: On the simulator, `UIApplication.openNotificationSettingsURLString` opens the `Settings` application instead of the application's notification settings screen.
linkString.link = URL(string: UIApplication.openNotificationSettingsURLString)
linkString.bold()
text.replace(linkPlaceholder, with: linkString)
return text
}()
func string(for mode: RoomNotificationModeProxy) -> String {
switch mode {
case .allMessages:
return L10n.screenNotificationSettingsModeAll
case .mentionsAndKeywordsOnly:
return L10n.screenNotificationSettingsModeMentions
case .mute:
return L10n.commonMute
}
}
}
enum NotificationSettingsScreenViewAction {
case changedEnableNotifications
case groupChatsTapped
case directChatsTapped
case roomMentionChanged
case callsChanged
case invitationsChanged
case showAllRoomListActivityChanged
case close
case fixConfigurationMismatchTapped
case selectAlertTone(NotificationTone)
case addedCustomAlertTone(Result<URL, Error>)
case deleteCustomAlertTones([NotificationTone])
}
enum NotificationSettingsScreenErrorType: Hashable {
/// A specific error message shown in an alert.
case alert
case fixMismatchConfigurationFailed
}