wip
This commit is contained in:
parent
944f38d301
commit
b910b2ac4b
|
@ -12,11 +12,13 @@ enum AttachmentType: Stateable {
|
||||||
case contact
|
case contact
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct AttachmentItem: Stateable {
|
||||||
|
let type: AttachmentType
|
||||||
|
let data: Data
|
||||||
|
let string: String
|
||||||
|
}
|
||||||
|
|
||||||
struct Attachment: Stateable {
|
struct Attachment: Stateable {
|
||||||
let id: String
|
let id: String
|
||||||
let type: AttachmentType
|
let items: [AttachmentItem]
|
||||||
let url: URL?
|
|
||||||
let data: [Data]?
|
|
||||||
let str: String?
|
|
||||||
let localPath: URL?
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,11 +98,7 @@ struct AttachmentMediaPickerView: View {
|
||||||
CameraPicker(sourceType: .camera) { data, type in
|
CameraPicker(sourceType: .camera) { data, type in
|
||||||
store.dispatch(.conversationAction(.sendAttachment(.init(
|
store.dispatch(.conversationAction(.sendAttachment(.init(
|
||||||
id: UUID().uuidString,
|
id: UUID().uuidString,
|
||||||
type: type,
|
items: [.init(type: type, data: data, string: "")]
|
||||||
url: nil,
|
|
||||||
data: [data],
|
|
||||||
str: nil,
|
|
||||||
localPath: nil
|
|
||||||
))))
|
))))
|
||||||
showCameraPicker = false
|
showCameraPicker = false
|
||||||
}
|
}
|
||||||
|
@ -238,7 +234,7 @@ struct AttachmentMediaPickerView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func sendGalleryMedia(ids: [String]) {
|
private func sendGalleryMedia(ids: [String]) {
|
||||||
var mediaData: [Data] = []
|
var media: [AttachmentItem] = []
|
||||||
let dispatchGroup = DispatchGroup()
|
let dispatchGroup = DispatchGroup()
|
||||||
|
|
||||||
let asset = PHAsset.fetchAssets(withLocalIdentifiers: ids, options: nil)
|
let asset = PHAsset.fetchAssets(withLocalIdentifiers: ids, options: nil)
|
||||||
|
@ -257,7 +253,7 @@ struct AttachmentMediaPickerView: View {
|
||||||
) { image, _ in
|
) { image, _ in
|
||||||
if let image {
|
if let image {
|
||||||
let data = image.jpegData(compressionQuality: 1.0) ?? Data()
|
let data = image.jpegData(compressionQuality: 1.0) ?? Data()
|
||||||
mediaData.append(data)
|
media.append(.init(type: .image, data: data, string: ""))
|
||||||
}
|
}
|
||||||
dispatchGroup.leave()
|
dispatchGroup.leave()
|
||||||
}
|
}
|
||||||
|
@ -271,7 +267,7 @@ struct AttachmentMediaPickerView: View {
|
||||||
if let avAsset {
|
if let avAsset {
|
||||||
let url = (avAsset as? AVURLAsset)?.url
|
let url = (avAsset as? AVURLAsset)?.url
|
||||||
let data = try? Data(contentsOf: url ?? URL(fileURLWithPath: ""))
|
let data = try? Data(contentsOf: url ?? URL(fileURLWithPath: ""))
|
||||||
mediaData.append(data ?? Data())
|
media.append(.init(type: .movie, data: data ?? Data(), string: ""))
|
||||||
}
|
}
|
||||||
dispatchGroup.leave()
|
dispatchGroup.leave()
|
||||||
}
|
}
|
||||||
|
@ -280,11 +276,7 @@ struct AttachmentMediaPickerView: View {
|
||||||
dispatchGroup.notify(queue: .main) {
|
dispatchGroup.notify(queue: .main) {
|
||||||
store.dispatch(.conversationAction(.sendAttachment(.init(
|
store.dispatch(.conversationAction(.sendAttachment(.init(
|
||||||
id: UUID().uuidString,
|
id: UUID().uuidString,
|
||||||
type: .image,
|
items: media
|
||||||
url: nil,
|
|
||||||
data: mediaData,
|
|
||||||
str: nil,
|
|
||||||
localPath: nil
|
|
||||||
))))
|
))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue