diff --git a/ConversationsClassic/AppCore/Actions/FileActions.swift b/ConversationsClassic/AppCore/Actions/FileActions.swift index 865dade..9acb339 100644 --- a/ConversationsClassic/AppCore/Actions/FileActions.swift +++ b/ConversationsClassic/AppCore/Actions/FileActions.swift @@ -1,7 +1,7 @@ import Foundation enum FileAction: Stateable { - case downloadAttachmentFile(id: String, remotePath: URL) + case downloadAttachmentFile(id: String, attachmentRemotePath: URL) case attachmentFileDownloaded(id: String, localUrl: URL) case downloadingAttachmentFileFailed(id: String, reason: String) diff --git a/ConversationsClassic/AppCore/Database/Database+Migrations.swift b/ConversationsClassic/AppCore/Database/Database+Migrations.swift index d2e1aaa..339e473 100644 --- a/ConversationsClassic/AppCore/Database/Database+Migrations.swift +++ b/ConversationsClassic/AppCore/Database/Database+Migrations.swift @@ -59,10 +59,10 @@ extension Database { table.column("pending", .boolean).notNull() table.column("sentError", .boolean).notNull() table.column("attachmentType", .integer) - table.column("localPath", .text) - table.column("remotePath", .text) - table.column("localThumbnailPath", .text) - table.column("downloadFailed", .boolean).notNull().defaults(to: false) + table.column("attachmentLocalPath", .text) + table.column("attachmentRemotePath", .text) + table.column("attachmentThumbnailPath", .text) + table.column("attachmentDownloadFailed", .boolean).notNull().defaults(to: false) } } diff --git a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift index 4dc73d1..f2a7beb 100644 --- a/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/DatabaseMiddleware.swift @@ -275,7 +275,7 @@ final class DatabaseMiddleware { _ = try database._db.write { db in try Message .filter(Column("id") == id) - .updateAll(db, Column("downloadFailed").set(to: false)) + .updateAll(db, Column("attachmentDownloadFailed").set(to: false)) } promise(.success(.empty)) } catch { @@ -298,7 +298,7 @@ final class DatabaseMiddleware { _ = try database._db.write { db in try Message .filter(Column("id") == id) - .updateAll(db, Column("localPath").set(to: localUrl)) + .updateAll(db, Column("attachmentLocalPath").set(to: localUrl)) } promise(.success(.empty)) } catch { @@ -321,7 +321,7 @@ final class DatabaseMiddleware { _ = try database._db.write { db in try Message .filter(Column("id") == id) - .updateAll(db, Column("localThumbnailPath").set(to: thumbnailUrl)) + .updateAll(db, Column("attachmentThumbnailPath").set(to: thumbnailUrl)) } promise(.success(.empty)) } catch { diff --git a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift index e859380..f1fc78b 100644 --- a/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/FileMiddleware.swift @@ -9,19 +9,19 @@ final class FileMiddleware { switch action { case .conversationAction(.messagesUpdated(let messages)): return Future { promise in - for message in messages where message.remotePath != nil && message.localPath == nil { + for message in messages where message.attachmentRemotePath != nil && message.attachmentLocalPath == nil { DispatchQueue.main.async { // swiftlint:disable:next force_unwrapping - store.dispatch(.fileAction(.downloadAttachmentFile(id: message.id, remotePath: message.remotePath!))) + store.dispatch(.fileAction(.downloadAttachmentFile(id: message.id, attachmentRemotePath: message.attachmentRemotePath!))) } } promise(.success(.empty)) }.eraseToAnyPublisher() - case .fileAction(.downloadAttachmentFile(let id, let remotePath)): + case .fileAction(.downloadAttachmentFile(let id, let attachmentRemotePath)): return Future { promise in - let localUrl = FileProcessing.fileFolder.appendingPathComponent(id).appendingPathExtension(remotePath.pathExtension) - DownloadManager.shared.enqueueDownload(from: remotePath, to: localUrl) { error in + let localUrl = FileProcessing.fileFolder.appendingPathComponent(id).appendingPathExtension(attachmentRemotePath.pathExtension) + DownloadManager.shared.enqueueDownload(from: attachmentRemotePath, to: localUrl) { error in DispatchQueue.main.async { if let error { store.dispatch(.fileAction(.downloadingAttachmentFileFailed(id: id, reason: error.localizedDescription))) diff --git a/ConversationsClassic/AppCore/Models/Message.swift b/ConversationsClassic/AppCore/Models/Message.swift index 1e45bb9..5f5eab1 100644 --- a/ConversationsClassic/AppCore/Models/Message.swift +++ b/ConversationsClassic/AppCore/Models/Message.swift @@ -42,10 +42,10 @@ struct Message: DBStorable, Equatable { let sentError: Bool var attachmentType: MessageAttachmentType? - var localPath: URL? - var remotePath: URL? - var localThumbnailPath: URL? - var downloadFailed: Bool = false + var attachmentLocalPath: URL? + var attachmentRemotePath: URL? + var attachmentThumbnailPath: URL? + var attachmentDownloadFailed: Bool = false } extension Message { @@ -96,14 +96,14 @@ extension Message { pending: false, sentError: false, attachmentType: nil, - localPath: nil, - remotePath: nil, - localThumbnailPath: nil, - downloadFailed: false + attachmentLocalPath: nil, + attachmentRemotePath: nil, + attachmentThumbnailPath: nil, + attachmentDownloadFailed: false ) if let oob = martinMessage.oob { msg.attachmentType = oob.attachmentType - msg.remotePath = URL(string: oob) + msg.attachmentRemotePath = URL(string: oob) } return msg } diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift b/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift index 1928fce..f670802 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationMessageContainer.swift @@ -82,7 +82,7 @@ private struct AttachmentView: View { } case .movie: - if let file = message.localPath { + if let file = message.attachmentLocalPath { VideoPlayerView(url: file) .frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize) .cornerRadius(Const.attachmentPreviewSize / 10) @@ -127,7 +127,7 @@ private struct AttachmentView: View { } private func thumbnail() -> Image? { - guard let thumbnailPath = message.localThumbnailPath else { return nil } + guard let thumbnailPath = message.attachmentThumbnailPath else { return nil } guard let uiImage = UIImage(contentsOfFile: thumbnailPath.path()) else { return nil } return Image(uiImage: uiImage) }