Get the instance-information to the exporter (IOS-117)

This commit is contained in:
Nathan Mattes 2023-08-25 16:33:18 +02:00
parent ec162d9796
commit 488ca727f9
6 changed files with 37 additions and 15 deletions

View File

@ -287,13 +287,16 @@ extension ComposeViewController {
// Look for images on the clipboard
if UIPasteboard.general.hasImages, let images = UIPasteboard.general.images {
logger.warning("Got image paste event, however attachments are not yet re-implemented.");
let mediaAttachmentSettings = viewModel.authContext.mastodonAuthenticationBox.authenticationRecord.object(in: viewModel.context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModels = images.map { image in
return AttachmentViewModel(
api: viewModel.context.apiService,
authContext: viewModel.authContext,
input: .image(image),
sizeLimit: composeContentViewModel.sizeLimit,
delegate: composeContentViewModel
delegate: composeContentViewModel,
mediaAttachmentSettings: mediaAttachmentSettings
)
}
composeContentViewModel.attachmentViewModels += attachmentViewModels

View File

@ -11,9 +11,10 @@ import AVKit
import MastodonCore
import SessionExporter
import Nuke
import MastodonSDK
extension AttachmentViewModel {
func compressVideo(url: URL) async throws -> URL? {
func compressVideo(url: URL, mediaAttachmentSettings: Mastodon.Entity.Instance.Configuration.MediaAttachments? = nil) async throws -> URL? {
let urlAsset = AVURLAsset(url: url)
guard let track = urlAsset.tracks(withMediaType: .video).first else {

View File

@ -49,6 +49,7 @@ final public class AttachmentViewModel: NSObject, ObservableObject, Identifiable
public let authContext: AuthContext
public let input: Input
public let sizeLimit: SizeLimit
private let mediaAttachmentSettings: Mastodon.Entity.Instance.Configuration.MediaAttachments?
@Published var caption = ""
@Published public private(set) var isCaptionEditable = true
@ -79,12 +80,14 @@ final public class AttachmentViewModel: NSObject, ObservableObject, Identifiable
authContext: AuthContext,
input: Input,
sizeLimit: SizeLimit,
delegate: AttachmentViewModelDelegate
delegate: AttachmentViewModelDelegate,
mediaAttachmentSettings: Mastodon.Entity.Instance.Configuration.MediaAttachments?
) {
self.api = api
self.authContext = authContext
self.input = input
self.sizeLimit = sizeLimit
self.mediaAttachmentSettings = mediaAttachmentSettings
self.delegate = delegate
super.init()
// end init
@ -158,7 +161,7 @@ final public class AttachmentViewModel: NSObject, ObservableObject, Identifiable
case .video(let fileURL, let mimeType):
self.output = output
self.update(uploadState: .compressing)
guard let compressedFileURL = try await compressVideo(url: fileURL) else {
guard let compressedFileURL = try await compressVideo(url: fileURL, mediaAttachmentSettings: mediaAttachmentSettings) else {
assertionFailure("Unable to compress video")
return
}

View File

@ -12,6 +12,7 @@ import Combine
import PhotosUI
import MastodonCore
import NaturalLanguage
import MastodonSDK
public final class ComposeContentViewController: UIViewController {
@ -480,6 +481,7 @@ extension ComposeContentViewController: UITableViewDelegate { }
extension ComposeContentViewController: PHPickerViewControllerDelegate {
public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true, completion: nil)
let mediaAttachmentSettings = viewModel.authContext.mastodonAuthenticationBox.authenticationRecord.object(in: viewModel.context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModels: [AttachmentViewModel] = results.map { result in
AttachmentViewModel(
@ -487,7 +489,8 @@ extension ComposeContentViewController: PHPickerViewControllerDelegate {
authContext: viewModel.authContext,
input: .pickerResult(result),
sizeLimit: viewModel.sizeLimit,
delegate: viewModel
delegate: viewModel,
mediaAttachmentSettings: mediaAttachmentSettings
)
}
viewModel.attachmentViewModels += attachmentViewModels
@ -501,12 +504,15 @@ extension ComposeContentViewController: UIImagePickerControllerDelegate & UINavi
guard let image = info[.originalImage] as? UIImage else { return }
let mediaAttachmentSettings = viewModel.authContext.mastodonAuthenticationBox.authenticationRecord.object(in: viewModel.context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModel = AttachmentViewModel(
api: viewModel.context.apiService,
authContext: viewModel.authContext,
input: .image(image),
sizeLimit: viewModel.sizeLimit,
delegate: viewModel
delegate: viewModel,
mediaAttachmentSettings: mediaAttachmentSettings
)
viewModel.attachmentViewModels += [attachmentViewModel]
}
@ -522,12 +528,15 @@ extension ComposeContentViewController: UIDocumentPickerDelegate {
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let url = urls.first else { return }
let mediaAttachmentSettings = viewModel.authContext.mastodonAuthenticationBox.authenticationRecord.object(in: viewModel.context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModel = AttachmentViewModel(
api: viewModel.context.apiService,
authContext: viewModel.authContext,
input: .url(url),
sizeLimit: viewModel.sizeLimit,
delegate: viewModel
delegate: viewModel,
mediaAttachmentSettings: mediaAttachmentSettings
)
viewModel.attachmentViewModels += [attachmentViewModel]
}

View File

@ -298,12 +298,15 @@ public final class ComposeContentViewModel: NSObject, ObservableObject {
self.isVisibilityButtonEnabled = false
self.attachmentViewModels = status.attachments.compactMap {
guard let assetURL = $0.assetURL, let url = URL(string: assetURL) else { return nil }
let mediaAttachmentSettings = authContext.mastodonAuthenticationBox.authenticationRecord.object(in: context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModel = AttachmentViewModel(
api: context.apiService,
authContext: authContext,
input: .mastodonAssetUrl(url, $0.id),
sizeLimit: sizeLimit,
delegate: self
delegate: self,
mediaAttachmentSettings: mediaAttachmentSettings
)
attachmentViewModel.caption = $0.altDescription ?? ""
return attachmentViewModel
@ -312,11 +315,6 @@ public final class ComposeContentViewModel: NSObject, ObservableObject {
bind()
}
deinit {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
}
}
extension ComposeContentViewModel {

View File

@ -279,22 +279,30 @@ extension ShareViewController {
}
if let movieProvider = _movieProvider {
let mediaAttachmentSettings = authContext.mastodonAuthenticationBox.authenticationRecord.object(in: context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModel = AttachmentViewModel(
api: context.apiService,
authContext: authContext,
input: .itemProvider(movieProvider),
sizeLimit: .init(image: nil, video: nil),
delegate: composeContentViewModel
delegate: composeContentViewModel,
mediaAttachmentSettings: mediaAttachmentSettings
)
composeContentViewModel.attachmentViewModels.append(attachmentViewModel)
} else if !imageProviders.isEmpty {
let mediaAttachmentSettings = authContext.mastodonAuthenticationBox.authenticationRecord.object(in: context.managedObjectContext)?.instance?.configurationV2?.mediaAttachments
let attachmentViewModels = imageProviders.map { provider in
AttachmentViewModel(
api: context.apiService,
authContext: authContext,
input: .itemProvider(provider),
sizeLimit: .init(image: nil, video: nil),
delegate: composeContentViewModel
delegate: composeContentViewModel,
mediaAttachmentSettings: mediaAttachmentSettings
)
}
composeContentViewModel.attachmentViewModels.append(contentsOf: attachmentViewModels)