damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit f14ba7cce4e0b5baf3bc210fad1423f32efebad7
parent 055b13c1cddcab01263b96758565aaa90fda6dbd
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 22 Apr 2023 12:11:31 -0700

Fix potentially buggy media uploader setting

Diffstat:
Mdamus/Views/ImagePicker.swift | 4++--
Mdamus/Views/PostView.swift | 6+++---
Mdamus/Views/Profile/EditProfilePictureControl.swift | 7+++----
Mdamus/Views/Profile/ProfilePictureSelector.swift | 6+++++-
4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/damus/Views/ImagePicker.swift b/damus/Views/ImagePicker.swift @@ -13,6 +13,7 @@ struct ImagePicker: UIViewControllerRepresentable { @Environment(\.presentationMode) private var presentationMode + let uploader: MediaUploader let sourceType: UIImagePickerController.SourceType let pubkey: String @Binding var image_upload_confirm: Bool @@ -108,9 +109,8 @@ struct ImagePicker: UIViewControllerRepresentable { func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController { let picker = UIImagePickerController() picker.sourceType = sourceType - let mediaUploader = get_media_uploader(pubkey) picker.mediaTypes = ["public.image", "com.compuserve.gif"] - if mediaUploader.supportsVideo && !imagesOnly { + if uploader.supportsVideo && !imagesOnly { picker.mediaTypes.append("public.movie") } picker.delegate = context.coordinator diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -246,7 +246,7 @@ struct PostView: View { } func handle_upload(media: MediaUpload) { - let uploader = get_media_uploader(damus_state.pubkey) + let uploader = damus_state.settings.default_media_uploader Task.init { let img = getImage(media: media) let res = await image_upload.start(media: media, uploader: uploader) @@ -336,7 +336,7 @@ struct PostView: View { } } .sheet(isPresented: $attach_media) { - ImagePicker(sourceType: .photoLibrary, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in + ImagePicker(uploader: damus_state.settings.default_media_uploader, sourceType: .photoLibrary, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in self.mediaToUpload = .image(img) } onVideoPicked: { url in self.mediaToUpload = .video(url) @@ -353,7 +353,7 @@ struct PostView: View { } .sheet(isPresented: $attach_camera) { // image_upload_confirm isn't handled here, I don't know we need to display it here too tbh - ImagePicker(sourceType: .camera, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in + ImagePicker(uploader: damus_state.settings.default_media_uploader, sourceType: .camera, pubkey: damus_state.pubkey, image_upload_confirm: $image_upload_confirm) { img in handle_upload(media: .image(img)) } onVideoPicked: { url in handle_upload(media: .video(url)) diff --git a/damus/Views/Profile/EditProfilePictureControl.swift b/damus/Views/Profile/EditProfilePictureControl.swift @@ -8,7 +8,7 @@ import SwiftUI struct EditProfilePictureControl: View { - + let uploader: MediaUploader let pubkey: String @Binding var profile_image: URL? @ObservedObject var viewModel: ProfileUploadingViewModel @@ -46,7 +46,7 @@ struct EditProfilePictureControl: View { } .sheet(isPresented: $show_camera) { // The alert may not be required for the profile pic upload case. Not showing the confirm check alert for this scenario - ImagePicker(sourceType: .camera, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in + ImagePicker(uploader: uploader, sourceType: .camera, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in handle_upload(media: .image(img)) } onVideoPicked: { url in print("Cannot upload videos as profile image") @@ -54,7 +54,7 @@ struct EditProfilePictureControl: View { } .sheet(isPresented: $show_library) { // The alert may not be required for the profile pic upload case. Not showing the confirm check alert for this scenario - ImagePicker(sourceType: .photoLibrary, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in + ImagePicker(uploader: uploader, sourceType: .photoLibrary, pubkey: pubkey, image_upload_confirm: $image_upload_confirm, imagesOnly: true) { img in handle_upload(media: .image(img)) } onVideoPicked: { url in print("Cannot upload videos as profile image") @@ -64,7 +64,6 @@ struct EditProfilePictureControl: View { private func handle_upload(media: MediaUpload) { viewModel.isLoading = true - let uploader = get_media_uploader(pubkey) Task { let res = await image_upload.start(media: media, uploader: uploader) diff --git a/damus/Views/Profile/ProfilePictureSelector.swift b/damus/Views/Profile/ProfilePictureSelector.swift @@ -23,11 +23,15 @@ struct ProfilePictureSelector: View { @State var profile_image: URL? = nil + var uploader: MediaUploader { + damus_state?.settings.default_media_uploader ?? .nostrBuild + } + var body: some View { let highlight: Highlight = .custom(Color.white, 2.0) ZStack { EditProfilePictureView(url: $profile_image, pubkey: pubkey, size: size, highlight: highlight, damus_state: damus_state) - EditProfilePictureControl(pubkey: pubkey, profile_image: $profile_image, viewModel: viewModel, callback: callback) + EditProfilePictureControl(uploader: uploader, pubkey: pubkey, profile_image: $profile_image, viewModel: viewModel, callback: callback) } } }