wip
This commit is contained in:
parent
f7eee58347
commit
37936b9903
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue