#748 - Implement methods for processing various media types and prepa… (#772)

* #748 - Implement methods for processing various media types and preparing them for upload

* Various tweaks following code review:
- added blurhash generation
- changed thumbnails to jpeg
- throwing if file size cannot be retrieved
- move MediaProvider files to separate folder so they can cleanly be imported in the NSE
- added audio file processing
- switched all image resizing methods to ImageIO
- various renames

* Fix blurhash formatting issues, `swift-format-ignore-file` doesn't work

* Processing all media within unique folders to avoid conflicts

* Fix various warnings

* Rename `sizeForItemAt(_ url: URL)` to `sizeForItem(at url: URL)`

* Remove unnecessary resizeImage(UIImage) method, start by copying not moving the file to the unique location

* Add back warning for roomDetails.avatarURL
This commit is contained in:
Stefan Ceriu
2023-04-21 12:13:36 +03:00
committed by GitHub
parent 88d3faf77d
commit 6700d4301d
21 changed files with 630 additions and 28 deletions
@@ -219,7 +219,8 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
var rooms = [HomeScreenRoom]()
var createdRoomIdentifiers = [String: Bool]()
#warning("This works around duplicated room list items coming out of the SDK, remove once fixed")
// This works around duplicated room list items which happens because the 2 different ss lists used
// update at different times. That will be fixed once we move this logic to the Rust side
func appendRoom(_ room: HomeScreenRoom, allRoomsProvider: Bool) {
guard createdRoomIdentifiers[room.id] == nil else {
MXLog.error("Built duplicated room for identifier: \(room.id). AllRoomsSummaryProvider: \(allRoomsProvider). Ignoring")
@@ -19,7 +19,7 @@ import SwiftUI
enum DocumentPickerAction {
case selectFile(URL)
case cancel
case error(DocumentPickerError)
case error(Error)
}
enum DocumentPickerError: Error {
@@ -62,11 +62,15 @@ struct DocumentPicker: UIViewControllerRepresentable {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let url = urls.first else {
documentPicker.callback(.error(.unknown))
documentPicker.callback(.error(DocumentPickerError.unknown))
return
}
documentPicker.callback(.selectFile(url))
do {
let newURL = try FileManager.default.copyFileToTemporaryDirectory(file: url)
documentPicker.callback(.selectFile(newURL))
} catch {
documentPicker.callback(.error(error))
}
}
}
}
@@ -69,7 +69,7 @@ struct PhotoLibraryPicker: UIViewControllerRepresentable {
do {
let _ = url.startAccessingSecurityScopedResource()
let newURL = try FileManager.default.copyFileToTemporaryDirectory(url: url)
let newURL = try FileManager.default.copyFileToTemporaryDirectory(file: url)
url.stopAccessingSecurityScopedResource()
Task { @MainActor in
@@ -94,7 +94,24 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
let mediaPickerPreviewScreenCoordinator = MediaPickerPreviewScreenCoordinator(parameters: .init(url: url, title: url.lastPathComponent)) { action in
switch action {
case .send:
self?.navigationStackCoordinator.setSheetCoordinator(nil)
Task {
let preprocessor = MediaUploadingPreprocessor()
switch await preprocessor.processMedia(at: url) {
case .success(let mediaInfo):
MXLog.info(mediaInfo)
switch mediaInfo {
case let .image(imageURL, thumbnailURL, imageInfo):
let _ = await self?.parameters.roomProxy.sendImage(url: imageURL, thumbnailURL: thumbnailURL, imageInfo: imageInfo)
default:
break
}
case .failure(let error):
MXLog.error("Failed processing media to upload with error: \(error)")
}
self?.navigationStackCoordinator.setSheetCoordinator(nil)
}
case .cancel:
self?.navigationStackCoordinator.setSheetCoordinator(nil)
}