Files
letro-ios/ElementX/Sources/ShareExtension/ShareExtensionModels.swift
Stefan Ceriu 0915cb81a8 Multi file uploads (#4358)
* Allow MediaPickerScreen users to select the media selection mode (single or multiple)

* Fix cancellation

* Add support for multiple media URLs on the MediaUploadPreviewScreen.

* Support processing more URLs on the `MediaUploadingPreprocessor` and sending more on the `MediaUploadPreviewScreen`

* Add feature flag for `multipleAttachmentUploadEnabled`

* Add a label showing the current preview item index in the MediaUploadPreviewScreen

* Add support for dragging and dropping or pasting multiple items at the same time.

* Support sharing more than one file through the share extension.

* Limit the number of items that can be shared in one go to 5.

* Fix unit tests

* Fix incorrect fatal error when dealing with single selection media pickers.

* Document the `multipleAttachmentUploadEnabled` usage in the context of the MediaPicker.

* Use a task group for processing selected media in the photo library picker.

* Use a task group for processing multiple selected media in the MediaUploadingPreprocessor

* Switch the maximum number of items that can be shared to 10.

* Allow multiple items to be pasted at the same time.
2025-07-30 15:44:05 +03:00

54 lines
1.8 KiB
Swift

//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Foundation
enum ShareExtensionConstants {
static let urlPath = "share"
}
enum ShareExtensionPayload: Hashable, Codable {
case mediaFiles(roomID: String?, mediaFiles: [ShareExtensionMediaFile])
case text(roomID: String?, text: String)
var roomID: String? {
switch self {
case .mediaFiles(let roomID, _),
.text(let roomID, _):
roomID
}
}
/// Moves any files in the payload from our `appGroupTemporaryDirectory` to the
/// system's `temporaryDirectory` returning a modified payload with updated file URLs.
func withDefaultTemporaryDirectory() throws -> Self {
switch self {
case .mediaFiles(let roomID, let mediaFiles):
return try .mediaFiles(roomID: roomID, mediaFiles: mediaFiles.map { mediaFile in
let path = mediaFile.url.path.replacing(URL.appGroupTemporaryDirectory.path, with: "").trimmingPrefix("/")
let newURL = URL.temporaryDirectory.appending(path: path)
try? FileManager.default.removeItem(at: newURL)
try FileManager.default.moveItem(at: mediaFile.url, to: newURL)
return mediaFile.replacingURL(with: newURL)
})
case .text:
return self
}
}
}
struct ShareExtensionMediaFile: Hashable, Codable {
let url: URL
let suggestedName: String?
fileprivate func replacingURL(with newURL: URL) -> ShareExtensionMediaFile {
ShareExtensionMediaFile(url: newURL, suggestedName: suggestedName)
}
}