Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve filenames on sharing #2605

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions deltachat-ios/Helper/FileHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,17 @@ public class FileHelper {
print("err: \(error.localizedDescription)")
}
}

static func copyIfPossible(src: URL, dest: URL) -> URL {
do {
if FileManager.default.fileExists(atPath: dest.path) {
try FileManager.default.removeItem(at: dest)
}
try FileManager.default.copyItem(at: src, to: dest)
return dest
} catch {
logger.error("cannot copy \(src) to \(dest)")
return src
}
}
}
17 changes: 13 additions & 4 deletions deltachat-ios/Helper/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,26 @@ struct Utils {
}

public static func share(message: DcMsg, parentViewController: UIViewController, sourceView: UIView? = nil, sourceItem: UIBarButtonItem? = nil) {
guard let fileURL = message.fileURL else { return }
guard let scrambledURL = message.fileURL else { return }

let shareURL: URL
if let filename = message.filename {
let cleanURL = FileManager.default.temporaryDirectory.appendingPathComponent(filename)
shareURL = FileHelper.copyIfPossible(src: scrambledURL, dest: cleanURL)
} else {
shareURL = scrambledURL
}

let objectsToShare: [Any]
if message.type == DC_MSG_WEBXDC {
let dict = message.getWebxdcInfoDict()
let previewImage = message.getWebxdcPreviewImage()
let previewText = dict["name"] as? String ?? fileURL.lastPathComponent
let previewText = dict["name"] as? String ?? shareURL.lastPathComponent
objectsToShare = [WebxdcItemSource(title: previewText,
previewImage: previewImage,
url: fileURL)]
url: shareURL)]
} else {
objectsToShare = [fileURL]
objectsToShare = [shareURL]
}

let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
Expand Down
Loading