Files
letro-ios/ElementX/Sources/Screens/RoomNotificationSettingsScreen/RoomNotificationSettingsScreenModels.swift
Mauro 6160c44d67 Update copyright holding and dates (#4640)
* Update copyright holding and dates

* compound IDE Macros updated

* update copyright

* update copyrights done

* update templates and README
2025-10-21 14:34:56 +02:00

132 lines
4.1 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
enum RoomNotificationSettingsScreenViewModelAction {
case openGlobalSettings
case dismiss
}
enum RoomNotificationSettingsState {
case loading
case loaded(settings: RoomNotificationSettingsProxyProtocol)
case error
}
extension RoomNotificationSettingsState {
var isLoading: Bool {
if case .loading = self {
return true
}
return false
}
var isLoaded: Bool {
if case .loaded = self {
return true
}
return false
}
var isError: Bool {
if case .error = self {
return true
}
return false
}
}
struct RoomNotificationSettingsScreenViewState: BindableState {
var bindings: RoomNotificationSettingsScreenViewStateBindings
let strings = RoomNotificationSettingsScreenStrings()
var notificationSettingsState: RoomNotificationSettingsState = .loading
var availableCustomRoomNotificationModes: [RoomNotificationModeProxy] = [.allMessages, .mentionsAndKeywordsOnly, .mute]
var isRestoringDefaultSetting = false
var pendingCustomMode: RoomNotificationModeProxy?
var displayAsUserDefinedRoomSettings = false
var navigationTitle: String
var customSettingsSectionHeader: String
var deletingCustomSetting = false
var shouldDisplayMentionsOnlyDisclaimer = true
func description(mode: RoomNotificationModeProxy) -> String? {
guard mode == .mentionsAndKeywordsOnly,
shouldDisplayMentionsOnlyDisclaimer else {
return nil
}
return L10n.screenRoomNotificationSettingsMentionsOnlyDisclaimer
}
func isSelected(mode: RoomNotificationModeProxy) -> Bool {
if case .loaded(let settings) = notificationSettingsState, settings.mode == mode, pendingCustomMode == nil {
return true
}
return false
}
}
struct RoomNotificationSettingsScreenViewStateBindings {
var allowCustomSetting = false
/// Information describing the currently displayed alert.
var alertInfo: AlertInfo<RoomNotificationSettingsScreenErrorType>?
}
enum RoomNotificationSettingsScreenViewAction {
case changedAllowCustomSettings
case setCustomMode(RoomNotificationModeProxy)
case customSettingFootnoteLinkTapped
case deleteCustomSettingTapped
}
struct RoomNotificationSettingsScreenStrings {
let customSettingFootnote: AttributedString
let customSettingFootnoteLink: URL?
init() {
customSettingFootnoteLink = URL(string: "element://openGlobalSettings")
let linkPlaceholder = "{link}"
var customSettingFootnote = AttributedString(L10n.screenRoomNotificationSettingsDefaultSettingFootnote(linkPlaceholder))
var linkString = AttributedString(L10n.screenRoomNotificationSettingsDefaultSettingFootnoteContentLink)
linkString.link = customSettingFootnoteLink
linkString.bold()
customSettingFootnote.replace(linkPlaceholder, with: linkString)
self.customSettingFootnote = customSettingFootnote
}
func string(for mode: RoomNotificationModeProxy) -> String {
switch mode {
case .allMessages:
return L10n.screenRoomNotificationSettingsModeAllMessages
case .mentionsAndKeywordsOnly:
return L10n.screenRoomNotificationSettingsModeMentionsAndKeywords
case .mute:
return L10n.commonMute
}
}
func string(for state: RoomNotificationSettingsState) -> String {
switch state {
case .loading:
return L10n.commonLoading
case .loaded(let settings):
return string(for: settings.mode)
case .error:
return L10n.commonError
}
}
}
enum RoomNotificationSettingsScreenErrorType: Hashable {
case loadingSettingsFailed
case setModeFailed
case restoreDefaultFailed
}