Skip to content

Commit

Permalink
preserve filenames on sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Feb 12, 2025
1 parent 5b36141 commit 8294843
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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

0 comments on commit 8294843

Please sign in to comment.