linphone-iphone/Linphone/UI/Main/Conversations/Model/Attachment.swift
2024-09-24 10:59:52 +02:00

98 lines
2.2 KiB
Swift

/*
* Copyright (c) 2010-2023 Belledonne Communications SARL.
*
* This file is part of linphone-iphone
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Foundation
public enum AttachmentType: String, Codable {
case image
case gif
case video
case audio
case voiceRecording
case pdf
case text
case fileTransfer
case other
public var title: String {
switch self {
case .image:
return "Image"
case .gif:
return "GIF"
case .video:
return "Video"
case .audio:
return "Audio"
case .voiceRecording:
return "Voice Recording"
case .pdf:
return "PDF"
case .text:
return "Text"
case .fileTransfer:
return "File Transfer"
default:
return "Other"
}
}
public init(mediaType: MediaType) {
switch mediaType {
case .image:
self = .image
case .gif:
self = .gif
case .video:
self = .video
case .audio:
self = .audio
case .voiceRecording:
self = .voiceRecording
case .pdf:
self = .pdf
case .text:
self = .text
case .fileTransfer:
self = .fileTransfer
default:
self = .other
}
}
}
public struct Attachment: Codable, Identifiable, Hashable {
public let id: String
public let name: String
public let thumbnail: URL
public let full: URL
public let type: AttachmentType
public init(id: String, name: String, thumbnail: URL, full: URL, type: AttachmentType) {
self.id = id
self.name = name
self.thumbnail = thumbnail
self.full = full
self.type = type
}
public init(id: String, name: String, url: URL, type: AttachmentType) {
self.init(id: id, name: name, thumbnail: url, full: url, type: type)
}
}