wip
This commit is contained in:
parent
18ea45257b
commit
14a83ca1d8
|
@ -27,10 +27,6 @@ final class DownloadManager {
|
||||||
|
|
||||||
if let tempLocalUrl = tempLocalUrl, error == nil {
|
if let tempLocalUrl = tempLocalUrl, error == nil {
|
||||||
do {
|
do {
|
||||||
let destinationDirectory = localUrl.deletingLastPathComponent()
|
|
||||||
if !FileManager.default.fileExists(atPath: destinationDirectory.path) {
|
|
||||||
try FileManager.default.createDirectory(at: destinationDirectory, withIntermediateDirectories: true, attributes: nil)
|
|
||||||
}
|
|
||||||
if FileManager.default.fileExists(atPath: localUrl.path) {
|
if FileManager.default.fileExists(atPath: localUrl.path) {
|
||||||
try FileManager.default.removeItem(at: localUrl)
|
try FileManager.default.removeItem(at: localUrl)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,18 @@ final class FileProcessing {
|
||||||
static var fileFolder: URL {
|
static var fileFolder: URL {
|
||||||
// swiftlint:disable:next force_unwrapping
|
// swiftlint:disable:next force_unwrapping
|
||||||
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||||
return documentsURL.appendingPathComponent(Const.fileFolder)
|
let subdirectoryURL = documentsURL.appendingPathComponent(Const.fileFolder)
|
||||||
|
if !FileManager.default.fileExists(atPath: subdirectoryURL.path) {
|
||||||
|
try? FileManager.default.createDirectory(at: subdirectoryURL, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
}
|
||||||
|
return subdirectoryURL
|
||||||
}
|
}
|
||||||
|
|
||||||
func createThumbnail(id: String, localUrl: URL) -> URL? {
|
func createThumbnail(localUrl: URL) -> URL? {
|
||||||
// make path for thumbnail
|
let fileExtension = localUrl.pathExtension
|
||||||
let thumbnailUrl = FileProcessing.fileFolder.appendingPathComponent(id).appendingPathExtension("png")
|
let fileNameWithoutExtension = localUrl.deletingPathExtension().lastPathComponent
|
||||||
|
let thumbnailFileName = fileNameWithoutExtension + "_thumb." + fileExtension
|
||||||
|
let thumbnailUrl = FileProcessing.fileFolder.appendingPathComponent(thumbnailFileName)
|
||||||
|
|
||||||
// check if thumbnail already exists
|
// check if thumbnail already exists
|
||||||
if FileManager.default.fileExists(atPath: thumbnailUrl.path) {
|
if FileManager.default.fileExists(atPath: thumbnailUrl.path) {
|
||||||
|
|
|
@ -263,6 +263,29 @@ final class DatabaseMiddleware {
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
|
|
||||||
// MARK: Attachments
|
// MARK: Attachments
|
||||||
|
case .fileAction(.downloadAttachmentFile(let id, _)):
|
||||||
|
return Future<AppAction, Never> { promise in
|
||||||
|
Task(priority: .background) { [weak self] in
|
||||||
|
guard let database = self?.database else {
|
||||||
|
promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: L10n.Global.Error.genericDbError)))
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
_ = try database._db.write { db in
|
||||||
|
try Message
|
||||||
|
.filter(Column("id") == id)
|
||||||
|
.updateAll(db, Column("attachmentDownloadFailed").set(to: false))
|
||||||
|
}
|
||||||
|
promise(.success(.empty))
|
||||||
|
} catch {
|
||||||
|
promise(.success(.databaseAction(.updateAttachmentFailed(id: id, reason: error.localizedDescription)))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
|
||||||
case .fileAction(.downloadingAttachmentFileFailed(let id, _)):
|
case .fileAction(.downloadingAttachmentFileFailed(let id, _)):
|
||||||
return Future<AppAction, Never> { promise in
|
return Future<AppAction, Never> { promise in
|
||||||
Task(priority: .background) { [weak self] in
|
Task(priority: .background) { [weak self] in
|
||||||
|
|
|
@ -51,7 +51,7 @@ final class FileMiddleware {
|
||||||
|
|
||||||
case .fileAction(.createAttachmentThumbnail(let id, let localUrl)):
|
case .fileAction(.createAttachmentThumbnail(let id, let localUrl)):
|
||||||
return Future { [weak self] promise in
|
return Future { [weak self] promise in
|
||||||
if let thumbnailUrl = FileProcessing.shared.createThumbnail(id: id, localUrl: localUrl) {
|
if let thumbnailUrl = FileProcessing.shared.createThumbnail(localUrl: localUrl) {
|
||||||
self?.downloadingMessageIDs.remove(id)
|
self?.downloadingMessageIDs.remove(id)
|
||||||
promise(.success(.fileAction(.attachmentThumbnailCreated(id: id, thumbnailUrl: thumbnailUrl))))
|
promise(.success(.fileAction(.attachmentThumbnailCreated(id: id, thumbnailUrl: thumbnailUrl))))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -33,7 +33,7 @@ enum Const {
|
||||||
static let videoDurationLimit = 60.0
|
static let videoDurationLimit = 60.0
|
||||||
|
|
||||||
// Upload/download file folder
|
// Upload/download file folder
|
||||||
static let fileFolder = "downloads"
|
static let fileFolder = "Downloads"
|
||||||
|
|
||||||
// Grid size for gallery preview (3 in a row)
|
// Grid size for gallery preview (3 in a row)
|
||||||
static let galleryGridSize = UIScreen.main.bounds.width / 3
|
static let galleryGridSize = UIScreen.main.bounds.width / 3
|
||||||
|
|
|
@ -134,7 +134,9 @@ private struct AttachmentView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
// TODO: Retry download
|
if let url = message.attachmentRemotePath {
|
||||||
|
store.dispatch(.fileAction(.downloadAttachmentFile(id: message.id, attachmentRemotePath: url)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ targets:
|
||||||
NSMicrophoneUsageDescription: Allow app to take sound from microphone for attachment video
|
NSMicrophoneUsageDescription: Allow app to take sound from microphone for attachment video
|
||||||
NSLocationWhenInUseUsageDescription: Allow app to take your geo to send it in attachment
|
NSLocationWhenInUseUsageDescription: Allow app to take your geo to send it in attachment
|
||||||
NSLocationAlwaysAndWhenInUseUsageDescription: Allow app to take your geo to send it in attachment
|
NSLocationAlwaysAndWhenInUseUsageDescription: Allow app to take your geo to send it in attachment
|
||||||
|
UISupportsDocumentBrowser: true
|
||||||
# UIViewControllerBasedStatusBarAppearance: NO
|
# UIViewControllerBasedStatusBarAppearance: NO
|
||||||
# UIStatusBarStyle: UIStatusBarStyleLightContent
|
# UIStatusBarStyle: UIStatusBarStyleLightContent
|
||||||
# NSFaceIDUsageDescription: Required for accessing to account info
|
# NSFaceIDUsageDescription: Required for accessing to account info
|
||||||
|
|
Loading…
Reference in a new issue