mv-experiment #1
|
@ -23,12 +23,12 @@ struct Attachment: Codable & Equatable, DatabaseValueConvertible {
|
||||||
|
|
||||||
var localPath: URL? {
|
var localPath: URL? {
|
||||||
guard let attachmentLocalName = localName else { return nil }
|
guard let attachmentLocalName = localName else { return nil }
|
||||||
return Const.fileFolder.appendingPathComponent(attachmentLocalName)
|
return FolderWrapper.shared.fileFolder.appendingPathComponent(attachmentLocalName)
|
||||||
}
|
}
|
||||||
|
|
||||||
var thumbnailPath: URL? {
|
var thumbnailPath: URL? {
|
||||||
guard let attachmentThumbnailName = thumbnailName else { return nil }
|
guard let attachmentThumbnailName = thumbnailName else { return nil }
|
||||||
return Const.fileFolder.appendingPathComponent(attachmentThumbnailName)
|
return FolderWrapper.shared.fileFolder.appendingPathComponent(attachmentThumbnailName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ extension AttachmentsStore {
|
||||||
guard let photo = try? await PHImageManager.default().getPhoto(for: asset) else { return }
|
guard let photo = try? await PHImageManager.default().getPhoto(for: asset) else { return }
|
||||||
guard let data = photo.jpegData(compressionQuality: 1.0) else { return }
|
guard let data = photo.jpegData(compressionQuality: 1.0) else { return }
|
||||||
let localName = "\(message.id)_\(UUID().uuidString).jpg"
|
let localName = "\(message.id)_\(UUID().uuidString).jpg"
|
||||||
let localUrl = Const.fileFolder.appendingPathComponent(localName)
|
let localUrl = FolderWrapper.shared.fileFolder.appendingPathComponent(localName)
|
||||||
try? data.write(to: localUrl)
|
try? data.write(to: localUrl)
|
||||||
message.contentType = .attachment(
|
message.contentType = .attachment(
|
||||||
Attachment(
|
Attachment(
|
||||||
|
@ -88,7 +88,7 @@ extension AttachmentsStore {
|
||||||
let assetURL = video as! AVURLAsset
|
let assetURL = video as! AVURLAsset
|
||||||
let url = assetURL.url
|
let url = assetURL.url
|
||||||
let localName = "\(message.id)_\(UUID().uuidString).mov"
|
let localName = "\(message.id)_\(UUID().uuidString).mov"
|
||||||
let localUrl = Const.fileFolder.appendingPathComponent(localName)
|
let localUrl = FolderWrapper.shared.fileFolder.appendingPathComponent(localName)
|
||||||
try? FileManager.default.copyItem(at: url, to: localUrl)
|
try? FileManager.default.copyItem(at: url, to: localUrl)
|
||||||
message.contentType = .attachment(
|
message.contentType = .attachment(
|
||||||
Attachment(
|
Attachment(
|
||||||
|
@ -130,7 +130,7 @@ extension AttachmentsStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
// save
|
// save
|
||||||
let localUrl = Const.fileFolder.appendingPathComponent(localName)
|
let localUrl = FolderWrapper.shared.fileFolder.appendingPathComponent(localName)
|
||||||
try data.write(to: localUrl)
|
try data.write(to: localUrl)
|
||||||
return (localName, msgType)
|
return (localName, msgType)
|
||||||
}.value
|
}.value
|
||||||
|
@ -164,7 +164,7 @@ extension AttachmentsStore {
|
||||||
let newMessageId = UUID().uuidString
|
let newMessageId = UUID().uuidString
|
||||||
let fileId = UUID().uuidString
|
let fileId = UUID().uuidString
|
||||||
let localName = "\(newMessageId)_\(fileId).\(extensions[index])"
|
let localName = "\(newMessageId)_\(fileId).\(extensions[index])"
|
||||||
let localUrl = Const.fileFolder.appendingPathComponent(localName)
|
let localUrl = FolderWrapper.shared.fileFolder.appendingPathComponent(localName)
|
||||||
do {
|
do {
|
||||||
try data.write(to: localUrl)
|
try data.write(to: localUrl)
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -215,19 +215,20 @@ private extension AttachmentsStore {
|
||||||
.filter { $0.contentType.isAttachment }
|
.filter { $0.contentType.isAttachment }
|
||||||
for message in forProcessing {
|
for message in forProcessing {
|
||||||
if case .attachment(let attachment) = message.contentType {
|
if case .attachment(let attachment) = message.contentType {
|
||||||
if attachment.localPath != nil, attachment.remotePath == nil {
|
let localPath = attachment.localPath
|
||||||
|
if localPath != nil, attachment.remotePath == nil {
|
||||||
// Uploading
|
// Uploading
|
||||||
self?.processing.insert(message.id)
|
self?.processing.insert(message.id)
|
||||||
Task {
|
Task {
|
||||||
await self?.uploadAttachment(message)
|
await self?.uploadAttachment(message)
|
||||||
}
|
}
|
||||||
} else if attachment.localPath == nil, attachment.remotePath != nil {
|
} else if localPath == nil, attachment.remotePath != nil {
|
||||||
// Downloading
|
// Downloading
|
||||||
self?.processing.insert(message.id)
|
self?.processing.insert(message.id)
|
||||||
Task {
|
Task {
|
||||||
await self?.downloadAttachment(message)
|
await self?.downloadAttachment(message)
|
||||||
}
|
}
|
||||||
} else if attachment.localPath != nil, attachment.remotePath != nil, attachment.thumbnailName == nil, attachment.type == .image {
|
} else if localPath != nil, attachment.remotePath != nil, attachment.thumbnailName == nil, attachment.type == .image {
|
||||||
// Generate thumbnail
|
// Generate thumbnail
|
||||||
self?.processing.insert(message.id)
|
self?.processing.insert(message.id)
|
||||||
Task {
|
Task {
|
||||||
|
@ -282,7 +283,7 @@ extension AttachmentsStore {
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let localName = "\(message.id)_\(UUID().uuidString).\(remoteUrl.lastPathComponent)"
|
let localName = "\(message.id)_\(UUID().uuidString).\(remoteUrl.lastPathComponent)"
|
||||||
let localUrl = Const.fileFolder.appendingPathComponent(localName)
|
let localUrl = FolderWrapper.shared.fileFolder.appendingPathComponent(localName)
|
||||||
|
|
||||||
// Download the file
|
// Download the file
|
||||||
let (tempUrl, _) = try await URLSession.shared.download(from: remoteUrl)
|
let (tempUrl, _) = try await URLSession.shared.download(from: remoteUrl)
|
||||||
|
@ -315,7 +316,7 @@ extension AttachmentsStore {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let thumbnailFileName = "thumb_\(localName)"
|
let thumbnailFileName = "thumb_\(localName)"
|
||||||
let thumbnailUrl = Const.fileFolder.appendingPathComponent(thumbnailFileName)
|
let thumbnailUrl = FolderWrapper.shared.fileFolder.appendingPathComponent(thumbnailFileName)
|
||||||
|
|
||||||
//
|
//
|
||||||
if !FileManager.default.fileExists(atPath: thumbnailUrl.path) {
|
if !FileManager.default.fileExists(atPath: thumbnailUrl.path) {
|
||||||
|
|
|
@ -14,17 +14,6 @@ enum Const {
|
||||||
Bundle.main.bundleIdentifier ?? "Conversations Classic iOS"
|
Bundle.main.bundleIdentifier ?? "Conversations Classic iOS"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Folder for storing files
|
|
||||||
static var fileFolder: URL {
|
|
||||||
// swiftlint:disable:next force_unwrapping
|
|
||||||
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
|
||||||
let subdirectoryURL = documentsURL.appendingPathComponent("Downloads")
|
|
||||||
if !FileManager.default.fileExists(atPath: subdirectoryURL.path) {
|
|
||||||
try? FileManager.default.createDirectory(at: subdirectoryURL, withIntermediateDirectories: true, attributes: nil)
|
|
||||||
}
|
|
||||||
return subdirectoryURL
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trusted servers
|
// Trusted servers
|
||||||
enum TrustedServers: String {
|
enum TrustedServers: String {
|
||||||
case narayana = "narayana.im"
|
case narayana = "narayana.im"
|
||||||
|
@ -46,3 +35,17 @@ enum Const {
|
||||||
// MAM request page size
|
// MAM request page size
|
||||||
static let mamRequestPageSize = 50
|
static let mamRequestPageSize = 50
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class FolderWrapper {
|
||||||
|
static let shared = FolderWrapper()
|
||||||
|
let fileFolder: URL
|
||||||
|
private init() {
|
||||||
|
// swiftlint:disable:next force_unwrapping
|
||||||
|
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||||
|
let subdirectoryURL = documentsURL.appendingPathComponent("Downloads")
|
||||||
|
if !FileManager.default.fileExists(atPath: subdirectoryURL.path) {
|
||||||
|
try? FileManager.default.createDirectory(at: subdirectoryURL, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
}
|
||||||
|
fileFolder = subdirectoryURL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -110,14 +110,15 @@ private struct AttachmentView: View {
|
||||||
} else {
|
} else {
|
||||||
switch attachment.type {
|
switch attachment.type {
|
||||||
case .image:
|
case .image:
|
||||||
if let thumbnail = thumbnail() {
|
AsyncImage(url: attachment.thumbnailPath) { image in
|
||||||
thumbnail
|
image
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
||||||
} else {
|
} placeholder: {
|
||||||
placeholder
|
placeholder
|
||||||
}
|
}
|
||||||
|
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
||||||
|
|
||||||
case .video:
|
case .video:
|
||||||
if let file = attachment.localPath {
|
if let file = attachment.localPath {
|
||||||
|
|
|
@ -29,8 +29,7 @@ struct MainTabScreen: View {
|
||||||
ContactsScreen()
|
ContactsScreen()
|
||||||
|
|
||||||
case .settings:
|
case .settings:
|
||||||
Color.green
|
SettingsScreen()
|
||||||
// SettingsScreen()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tab bar
|
// Tab bar
|
||||||
|
|
16
ConversationsClassic/View/Main/Settings/SettingsScreen.swift
Normal file
16
ConversationsClassic/View/Main/Settings/SettingsScreen.swift
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct SettingsScreen: View {
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
// bg
|
||||||
|
Color.Material.Background.light
|
||||||
|
.ignoresSafeArea()
|
||||||
|
|
||||||
|
// content
|
||||||
|
Text("Soon!")
|
||||||
|
.font(.head1l)
|
||||||
|
.foregroundColor(.Material.Elements.active)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue