|
@@ -323,12 +323,24 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
|
|
|
content.userInfo = ui
|
|
|
content.sound = .default
|
|
|
|
|
|
- /*if let url = msg.fileURL,
|
|
|
- let attachment = try? UNNotificationAttachment(identifier: Constants.notificationIdentifier, url: url, options: nil) {
|
|
|
- content.attachments = [attachment]
|
|
|
- }*/
|
|
|
-
|
|
|
- let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)
|
|
|
+ if msg.type == DC_MSG_IMAGE || msg.type == DC_MSG_GIF,
|
|
|
+ let url = msg.fileURL {
|
|
|
+ do {
|
|
|
+ // make a copy of the file first since UNNotificationAttachment will move attached files into the attachment data store
|
|
|
+ // so that they can be accessed by all of the appropriate processes
|
|
|
+ let tempUrl = url.deletingLastPathComponent()
|
|
|
+ .appendingPathComponent("notification_tmp")
|
|
|
+ .appendingPathExtension(url.pathExtension)
|
|
|
+ try FileManager.default.copyItem(at: url, to: tempUrl)
|
|
|
+ if let attachment = try? UNNotificationAttachment(identifier: Constants.notificationIdentifier, url: tempUrl, options: nil) {
|
|
|
+ content.attachments = [attachment]
|
|
|
+ }
|
|
|
+ } catch let error {
|
|
|
+ logger.error("Failed to copy file \(url) for notification preview generation: \(error)")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
|
|
|
let request = UNNotificationRequest(identifier: Constants.notificationIdentifier, content: content, trigger: trigger)
|
|
|
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
|
|
|
DcContext.shared.logger?.info("notifications: added \(content)")
|