Fix Damus sharing issues

1. While sharing images/videos from Apple's Message app, the file will be treated as a Link with file-url. The if-else ordering will help to fix the issue.
2. While sharing image from Signal and Facebook app, the file being received is an UIImage and error is being sent. This PR fixes the issue.

Changelog-Fixed: Fix damus sharing issues
Signed-off-by: Swift Coder  <scoder1747@gmail.com>
This commit is contained in:
Swift Coder
2024-11-20 09:23:48 -05:00
committed by Daniel D’Aquino
parent 960c84d02e
commit 8c321e479b

View File

@@ -276,15 +276,7 @@ struct ShareExtensionView: View {
// Iterate through all attachments to handle multiple images // Iterate through all attachments to handle multiple images
for itemProvider in extensionItem.attachments ?? [] { for itemProvider in extensionItem.attachments ?? [] {
if itemProvider.hasItemConformingToTypeIdentifier(UTType.url.identifier) { if itemProvider.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { (item, error) in
if let url = item as? URL {
self.share_state = .loaded(ShareContent(title: title, content: .link(url)))
} else {
self.share_state = .failed(error: "Failed to load text content")
}
}
} else if itemProvider.hasItemConformingToTypeIdentifier(UTType.image.identifier) {
itemProvider.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil) { (item, error) in itemProvider.loadItem(forTypeIdentifier: UTType.image.identifier, options: nil) { (item, error) in
if let url = item as? URL { if let url = item as? URL {
@@ -294,7 +286,9 @@ struct ShareExtensionView: View {
unprocessedEnum: {.unprocessed_image($0)}, unprocessedEnum: {.unprocessed_image($0)},
processedEnum: {.processed_image($0)}) processedEnum: {.processed_image($0)})
} else if let image = item as? UIImage {
// process it directly if shared item is uiimage (example: image shared from Facebook, Signal apps)
chooseMedia(PreUploadedMedia.uiimage(image))
} else { } else {
self.share_state = .failed(error: "Failed to load image content") self.share_state = .failed(error: "Failed to load image content")
} }
@@ -313,6 +307,14 @@ struct ShareExtensionView: View {
self.share_state = .failed(error: "Failed to load video content") self.share_state = .failed(error: "Failed to load video content")
} }
} }
} else if itemProvider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { (item, error) in
if let url = item as? URL {
self.share_state = .loaded(ShareContent(title: title, content: .link(url)))
} else {
self.share_state = .failed(error: "Failed to load text content")
}
}
} else { } else {
share_state = .no_content share_state = .no_content
} }