Download this file
| 1 | import Foundation |
| 2 | |
| 3 | // đŸ¤– The app side of the share extension's handoff: shared images/videos wait |
| 4 | // in the app-group inbox until the app activates, shows the chat picker, and |
| 5 | // stages them into the chosen chat's composer (where they encrypt + upload |
| 6 | // exactly like a picked photo). Files are deleted once staged. |
| 7 | enum ShareInbox { |
| 8 | static let appGroup = "group.com.elevenmessenger.messenger" |
| 9 | |
| 10 | static var inboxURL: URL? { |
| 11 | FileManager.default |
| 12 | .containerURL(forSecurityApplicationGroupIdentifier: appGroup)? |
| 13 | .appendingPathComponent("share-inbox", isDirectory: true) |
| 14 | } |
| 15 | |
| 16 | /// Waiting shared files (oldest first), empty when there's nothing. |
| 17 | static func pending() -> [URL] { |
| 18 | guard let dir = inboxURL, |
| 19 | let files = try? FileManager.default.contentsOfDirectory( |
| 20 | at: dir, includingPropertiesForKeys: [.creationDateKey]) else { return [] } |
| 21 | return files.sorted { a, b in |
| 22 | let da = (try? a.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast |
| 23 | let db = (try? b.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast |
| 24 | return da < db |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | static func clear(_ urls: [URL]) { |
| 29 | for url in urls { try? FileManager.default.removeItem(at: url) } |
| 30 | } |
| 31 | } |
| 32 | |