another.im-ios/ConversationsClassic/AppCore/Models/Attachment.swift
2024-07-11 15:59:24 +02:00

49 lines
1.1 KiB
Swift

import Foundation
import GRDB
import Martin
import SwiftUI
enum AttachmentType: Int, Stateable, DatabaseValueConvertible {
case movie = 0
case image = 1
case audio = 2
case file = 3
}
struct Attachment: DBStorable {
static let databaseTableName = "attachments"
let id: String
let type: AttachmentType
let localPath: URL?
let remotePath: URL?
let localThumbnailPath: URL?
let messageId: String
static let message = belongsTo(Message.self)
var message: QueryInterfaceRequest<Message> {
request(for: Attachment.message)
}
}
extension Attachment: Equatable {}
extension String {
var attachmentType: AttachmentType {
let ext = (self as NSString).pathExtension.lowercased()
switch ext {
case "mov", "mp4", "avi":
return .movie
case "jpg", "png", "gif":
return .image
case "mp3", "wav", "m4a":
return .audio
case "txt", "doc", "pdf":
return .file
default:
return .file // Default to .file if the extension is not recognized
}
}
}