From 485071162c3389fa8ef4ed314388ac28deff1237 Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 10 Jul 2024 16:48:18 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/SharingActions.swift | 18 +++++++++++- .../AppCore/Models/ShareItem.swift | 10 ------- .../AttachmentContactsPickerView.swift | 9 +----- .../AttachmentFilesPickerView.swift | 28 +++++++++---------- .../AttachmentLocationPickerView.swift | 9 +----- .../AttachmentMediaPickerView.swift | 0 6 files changed, 32 insertions(+), 42 deletions(-) delete mode 100644 ConversationsClassic/AppCore/Models/ShareItem.swift rename ConversationsClassic/View/Screens/Attachments/{Media => }/AttachmentMediaPickerView.swift (100%) diff --git a/ConversationsClassic/AppCore/Actions/SharingActions.swift b/ConversationsClassic/AppCore/Actions/SharingActions.swift index 55e7166..64293e7 100644 --- a/ConversationsClassic/AppCore/Actions/SharingActions.swift +++ b/ConversationsClassic/AppCore/Actions/SharingActions.swift @@ -1,7 +1,23 @@ -enum SharingAction: Codable { +import Foundation + +enum SharingAction: Stateable { case showSharing(Bool) + case shareLocation(lat: Double, lon: Double) + + case shareContact(jid: String) + + case shareDocuments([Data]) + // case sendAttachment([ShareItem]) // case sendAttachmentDone // case sendAttachmentError(reason: String) } + +// struct ShareItem: Stateable { +// let id: String +// let type: AttachmentType +// let data: Data +// let thumbnail: Data +// let string: String +// } diff --git a/ConversationsClassic/AppCore/Models/ShareItem.swift b/ConversationsClassic/AppCore/Models/ShareItem.swift deleted file mode 100644 index e037b72..0000000 --- a/ConversationsClassic/AppCore/Models/ShareItem.swift +++ /dev/null @@ -1,10 +0,0 @@ -import Foundation -import SwiftUI - -struct ShareItem: Stateable { - let id: String - let type: AttachmentType - let data: Data - let thumbnail: Data - let string: String -} diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift index 6916235..77aa04e 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentContactsPickerView.swift @@ -40,14 +40,7 @@ struct AttachmentContactsPickerView: View { .clipped() .onTapGesture { if let selectedContact = selectedContact { - // TODO: fix it - // store.dispatch(.conversationAction(.sendAttachment([.init( - // id: UUID().uuidString, - // type: .contact, - // data: Data(), - // thumbnail: Data(), - // string: selectedContact.contactBareJid - // )]))) + store.dispatch(.sharingAction(.shareContact(jid: selectedContact.contactBareJid))) store.dispatch(.sharingAction(.showSharing(false))) } } diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift index 8ab6d7e..5d236fd 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift @@ -6,19 +6,9 @@ struct AttachmentFilesPickerView: View { var body: some View { DocumentPicker( - completion: { arr in - let sharedFiles = arr.map { - ShareItem( - id: UUID().uuidString, - type: .file, - data: $0, - thumbnail: Data(), - string: "" - ) - } - // TODO: Send files - // store.dispatch(.conversationAction(.sendAttachment(sharedFiles))) + completion: { dataArray in store.dispatch(.sharingAction(.showSharing(false))) + store.dispatch(.sharingAction(.shareDocuments(dataArray))) }, cancel: { store.dispatch(.sharingAction(.showSharing(false))) @@ -52,9 +42,17 @@ struct DocumentPicker: UIViewControllerRepresentable { self.parent = parent } - func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) { - // TODO: Send documents - // Handle the selected files + func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt: [URL]) { + var dataArray = [Data]() + for url in didPickDocumentsAt { + do { + let data = try Data(contentsOf: url) + dataArray.append(data) + } catch { + print("Unable to load data from \(url): \(error)") + } + } + parent.completion(dataArray) } func documentPickerWasCancelled(_: UIDocumentPickerViewController) { diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift index 679e10e..56abfa4 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift @@ -62,14 +62,7 @@ struct AttachmentLocationPickerView: View { } .clipped() .onTapGesture { - // TODO: Send location - // store.dispatch(.conversationAction(.sendAttachment([.init( - // id: UUID().uuidString, - // type: .location, - // data: Data(), - // thumbnail: Data(), - // string: "\(region.center.latitude),\(region.center.longitude)" - // )]))) + store.dispatch(.sharingAction(.shareLocation(lat: region.center.latitude, lon: region.center.longitude))) store.dispatch(.sharingAction(.showSharing(false))) } } diff --git a/ConversationsClassic/View/Screens/Attachments/Media/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift similarity index 100% rename from ConversationsClassic/View/Screens/Attachments/Media/AttachmentMediaPickerView.swift rename to ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift