import Foundation // 🤖 The app side of the share extension's handoff: shared images/videos wait // in the app-group inbox until the app activates, shows the chat picker, and // stages them into the chosen chat's composer (where they encrypt + upload // exactly like a picked photo). Files are deleted once staged. enum ShareInbox { static let appGroup = "group.com.elevenmessenger.messenger" static var inboxURL: URL? { FileManager.default .containerURL(forSecurityApplicationGroupIdentifier: appGroup)? .appendingPathComponent("share-inbox", isDirectory: true) } /// Waiting shared files (oldest first), empty when there's nothing. static func pending() -> [URL] { guard let dir = inboxURL, let files = try? FileManager.default.contentsOfDirectory( at: dir, includingPropertiesForKeys: [.creationDateKey]) else { return [] } return files.sorted { a, b in let da = (try? a.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast let db = (try? b.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? .distantPast return da < db } } static func clear(_ urls: [URL]) { for url in urls { try? FileManager.default.removeItem(at: url) } } }