wip
This commit is contained in:
parent
944f38d301
commit
b910b2ac4b
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue