wip
This commit is contained in:
parent
f7eee58347
commit
37936b9903
|
@ -1,7 +1,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum FileAction: Stateable {
|
enum FileAction: Stateable {
|
||||||
case downloadAttachmentFile(id: String, remotePath: URL)
|
case downloadAttachmentFile(id: String, attachmentRemotePath: URL)
|
||||||
case attachmentFileDownloaded(id: String, localUrl: URL)
|
case attachmentFileDownloaded(id: String, localUrl: URL)
|
||||||
case downloadingAttachmentFileFailed(id: String, reason: String)
|
case downloadingAttachmentFileFailed(id: String, reason: String)
|
||||||
|
|
||||||
|
|
|
@ -59,10 +59,10 @@ extension Database {
|
||||||
table.column("pending", .boolean).notNull()
|
table.column("pending", .boolean).notNull()
|
||||||
table.column("sentError", .boolean).notNull()
|
table.column("sentError", .boolean).notNull()
|
||||||
table.column("attachmentType", .integer)
|
table.column("attachmentType", .integer)
|
||||||
table.column("localPath", .text)
|
table.column("attachmentLocalPath", .text)
|
||||||
table.column("remotePath", .text)
|
table.column("attachmentRemotePath", .text)
|
||||||
table.column("localThumbnailPath", .text)
|
table.column("attachmentThumbnailPath", .text)
|
||||||
table.column("downloadFailed", .boolean).notNull().defaults(to: false)
|
table.column("attachmentDownloadFailed", .boolean).notNull().defaults(to: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ final class DatabaseMiddleware {
|
||||||
_ = try database._db.write { db in
|
_ = try database._db.write { db in
|
||||||
try Message
|
try Message
|
||||||
.filter(Column("id") == id)
|
.filter(Column("id") == id)
|
||||||
.updateAll(db, Column("downloadFailed").set(to: false))
|
.updateAll(db, Column("attachmentDownloadFailed").set(to: false))
|
||||||
}
|
}
|
||||||
promise(.success(.empty))
|
promise(.success(.empty))
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -298,7 +298,7 @@ final class DatabaseMiddleware {
|
||||||
_ = try database._db.write { db in
|
_ = try database._db.write { db in
|
||||||
try Message
|
try Message
|
||||||
.filter(Column("id") == id)
|
.filter(Column("id") == id)
|
||||||
.updateAll(db, Column("localPath").set(to: localUrl))
|
.updateAll(db, Column("attachmentLocalPath").set(to: localUrl))
|
||||||
}
|
}
|
||||||
promise(.success(.empty))
|
promise(.success(.empty))
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -321,7 +321,7 @@ final class DatabaseMiddleware {
|
||||||
_ = try database._db.write { db in
|
_ = try database._db.write { db in
|
||||||
try Message
|
try Message
|
||||||
.filter(Column("id") == id)
|
.filter(Column("id") == id)
|
||||||
.updateAll(db, Column("localThumbnailPath").set(to: thumbnailUrl))
|
.updateAll(db, Column("attachmentThumbnailPath").set(to: thumbnailUrl))
|
||||||
}
|
}
|
||||||
promise(.success(.empty))
|
promise(.success(.empty))
|
||||||
} catch {
|
} catch {
|
||||||
|
|
|
@ -9,19 +9,19 @@ final class FileMiddleware {
|
||||||
switch action {
|
switch action {
|
||||||
case .conversationAction(.messagesUpdated(let messages)):
|
case .conversationAction(.messagesUpdated(let messages)):
|
||||||
return Future { promise in
|
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 {
|
DispatchQueue.main.async {
|
||||||
// swiftlint:disable:next force_unwrapping
|
// 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))
|
promise(.success(.empty))
|
||||||
}.eraseToAnyPublisher()
|
}.eraseToAnyPublisher()
|
||||||
|
|
||||||
case .fileAction(.downloadAttachmentFile(let id, let remotePath)):
|
case .fileAction(.downloadAttachmentFile(let id, let attachmentRemotePath)):
|
||||||
return Future { promise in
|
return Future { promise in
|
||||||
let localUrl = FileProcessing.fileFolder.appendingPathComponent(id).appendingPathExtension(remotePath.pathExtension)
|
let localUrl = FileProcessing.fileFolder.appendingPathComponent(id).appendingPathExtension(attachmentRemotePath.pathExtension)
|
||||||
DownloadManager.shared.enqueueDownload(from: remotePath, to: localUrl) { error in
|
DownloadManager.shared.enqueueDownload(from: attachmentRemotePath, to: localUrl) { error in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if let error {
|
if let error {
|
||||||
store.dispatch(.fileAction(.downloadingAttachmentFileFailed(id: id, reason: error.localizedDescription)))
|
store.dispatch(.fileAction(.downloadingAttachmentFileFailed(id: id, reason: error.localizedDescription)))
|
||||||
|
|
|
@ -42,10 +42,10 @@ struct Message: DBStorable, Equatable {
|
||||||
let sentError: Bool
|
let sentError: Bool
|
||||||
|
|
||||||
var attachmentType: MessageAttachmentType?
|
var attachmentType: MessageAttachmentType?
|
||||||
var localPath: URL?
|
var attachmentLocalPath: URL?
|
||||||
var remotePath: URL?
|
var attachmentRemotePath: URL?
|
||||||
var localThumbnailPath: URL?
|
var attachmentThumbnailPath: URL?
|
||||||
var downloadFailed: Bool = false
|
var attachmentDownloadFailed: Bool = false
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Message {
|
extension Message {
|
||||||
|
@ -96,14 +96,14 @@ extension Message {
|
||||||
pending: false,
|
pending: false,
|
||||||
sentError: false,
|
sentError: false,
|
||||||
attachmentType: nil,
|
attachmentType: nil,
|
||||||
localPath: nil,
|
attachmentLocalPath: nil,
|
||||||
remotePath: nil,
|
attachmentRemotePath: nil,
|
||||||
localThumbnailPath: nil,
|
attachmentThumbnailPath: nil,
|
||||||
downloadFailed: false
|
attachmentDownloadFailed: false
|
||||||
)
|
)
|
||||||
if let oob = martinMessage.oob {
|
if let oob = martinMessage.oob {
|
||||||
msg.attachmentType = oob.attachmentType
|
msg.attachmentType = oob.attachmentType
|
||||||
msg.remotePath = URL(string: oob)
|
msg.attachmentRemotePath = URL(string: oob)
|
||||||
}
|
}
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ private struct AttachmentView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
case .movie:
|
case .movie:
|
||||||
if let file = message.localPath {
|
if let file = message.attachmentLocalPath {
|
||||||
VideoPlayerView(url: file)
|
VideoPlayerView(url: file)
|
||||||
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
.frame(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
|
||||||
.cornerRadius(Const.attachmentPreviewSize / 10)
|
.cornerRadius(Const.attachmentPreviewSize / 10)
|
||||||
|
@ -127,7 +127,7 @@ private struct AttachmentView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func thumbnail() -> Image? {
|
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 }
|
guard let uiImage = UIImage(contentsOfFile: thumbnailPath.path()) else { return nil }
|
||||||
return Image(uiImage: uiImage)
|
return Image(uiImage: uiImage)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue