Files
letro-ios/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.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

87 lines
2.3 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 CreateRoomScreenErrorType: Error {
case failedCreatingRoom
case failedUploadingMedia
case fileTooLarge
case mediaFileError
case unknown
}
enum CreateRoomViewModelAction {
case openRoom(withIdentifier: String)
case deselectUser(UserProfileProxy)
case updateDetails(CreateRoomFlowParameters)
case displayMediaPicker
case displayCameraPicker
case removeImage
}
struct CreateRoomViewState: BindableState {
var roomName: String
let serverName: String
let isKnockingFeatureEnabled: Bool
var selectedUsers: [UserProfileProxy]
var aliasLocalPart: String
var bindings: CreateRoomViewStateBindings
var avatarURL: URL?
var canCreateRoom: Bool {
!roomName.isEmpty && aliasErrors.isEmpty
}
var aliasErrors: Set<CreateRoomAliasErrorState> = []
var aliasErrorDescription: String? {
if aliasErrors.contains(.alreadyExists) {
L10n.errorRoomAddressAlreadyExists
} else if aliasErrors.contains(.invalidSymbols) {
L10n.errorRoomAddressInvalidSymbols
} else {
nil
}
}
}
struct CreateRoomViewStateBindings {
var roomTopic: String
var isRoomPrivate: Bool
var isKnockingOnly: Bool
var showAttachmentConfirmationDialog = false
/// Information describing the currently displayed alert.
var alertInfo: AlertInfo<CreateRoomScreenErrorType>?
}
enum CreateRoomViewAction {
case createRoom
case deselectUser(UserProfileProxy)
case displayCameraPicker
case displayMediaPicker
case removeImage
case updateRoomName(String)
case updateAliasLocalPart(String)
}
enum CreateRoomAliasErrorState {
case alreadyExists
case invalidSymbols
}
extension Set<CreateRoomAliasErrorState> {
var errorDescription: String? {
if contains(.alreadyExists) {
return L10n.errorRoomAddressAlreadyExists
} else if contains(.invalidSymbols) {
return L10n.errorRoomAddressInvalidSymbols
}
return nil
}
}