diff --git a/ConversationsClassic/AppCore/Models/Attachment.swift b/ConversationsClassic/AppCore/Models/Attachment.swift index 137e8cd..2c008ed 100644 --- a/ConversationsClassic/AppCore/Models/Attachment.swift +++ b/ConversationsClassic/AppCore/Models/Attachment.swift @@ -12,11 +12,13 @@ enum AttachmentType: Stateable { case contact } +struct AttachmentItem: Stateable { + let type: AttachmentType + let data: Data + let string: String +} + struct Attachment: Stateable { let id: String - let type: AttachmentType - let url: URL? - let data: [Data]? - let str: String? - let localPath: URL? + let items: [AttachmentItem] } diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift index 0851250..c09d2b7 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift @@ -98,11 +98,7 @@ struct AttachmentMediaPickerView: View { CameraPicker(sourceType: .camera) { data, type in store.dispatch(.conversationAction(.sendAttachment(.init( id: UUID().uuidString, - type: type, - url: nil, - data: [data], - str: nil, - localPath: nil + items: [.init(type: type, data: data, string: "")] )))) showCameraPicker = false } @@ -238,7 +234,7 @@ struct AttachmentMediaPickerView: View { } private func sendGalleryMedia(ids: [String]) { - var mediaData: [Data] = [] + var media: [AttachmentItem] = [] let dispatchGroup = DispatchGroup() let asset = PHAsset.fetchAssets(withLocalIdentifiers: ids, options: nil) @@ -257,7 +253,7 @@ struct AttachmentMediaPickerView: View { ) { image, _ in if let image { let data = image.jpegData(compressionQuality: 1.0) ?? Data() - mediaData.append(data) + media.append(.init(type: .image, data: data, string: "")) } dispatchGroup.leave() } @@ -271,7 +267,7 @@ struct AttachmentMediaPickerView: View { if let avAsset { let url = (avAsset as? AVURLAsset)?.url let data = try? Data(contentsOf: url ?? URL(fileURLWithPath: "")) - mediaData.append(data ?? Data()) + media.append(.init(type: .movie, data: data ?? Data(), string: "")) } dispatchGroup.leave() } @@ -280,11 +276,7 @@ struct AttachmentMediaPickerView: View { dispatchGroup.notify(queue: .main) { store.dispatch(.conversationAction(.sendAttachment(.init( id: UUID().uuidString, - type: .image, - url: nil, - data: mediaData, - str: nil, - localPath: nil + items: media )))) } }