Move media file loading logic to the SDK. (#702)

* Adopt getMediaFile for media previewing.
This commit is contained in:
Doug
2023-03-20 14:51:33 +00:00
committed by GitHub
parent bbd64092e7
commit efdb47a98a
42 changed files with 427 additions and 519 deletions
@@ -130,7 +130,6 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
return MediaProvider(mediaLoader: MediaLoader(client: client),
imageCache: .onlyOnDisk,
fileCache: FileCache.default,
backgroundTaskService: nil)
}
@@ -171,7 +171,7 @@ extension NotificationItemProxy {
notification.body = "📷 " + content.body
notification = try await notification.addMediaAttachment(using: mediaProvider,
mediaSource: .init(source: content.source))
mediaSource: .init(source: content.source, mimeType: content.info?.mimetype))
return notification
}
@@ -186,7 +186,7 @@ extension NotificationItemProxy {
notification.body = "📹 " + content.body
notification = try await notification.addMediaAttachment(using: mediaProvider,
mediaSource: .init(source: content.source))
mediaSource: .init(source: content.source, mimeType: content.info?.mimetype))
return notification
}
@@ -24,11 +24,10 @@ extension UNMutableNotificationContent {
guard let mediaProvider else {
return self
}
switch await mediaProvider.loadFileFromSource(mediaSource, fileExtension: "") {
case .success(let url):
switch await mediaProvider.loadFileFromSource(mediaSource) {
case .success(let file):
let attachment = try UNNotificationAttachment(identifier: ProcessInfo.processInfo.globallyUniqueString,
url: url,
url: file.url, // Needs testing: Does the file get copied before the media handle is be dropped?
options: nil)
attachments.append(attachment)
case .failure(let error):
@@ -47,14 +46,14 @@ extension UNMutableNotificationContent {
return self
}
switch await mediaProvider.loadFileFromSource(mediaSource, fileExtension: "jpg") {
case .success(let url):
switch await mediaProvider.loadFileFromSource(mediaSource) {
case .success(let mediaFile):
// Initialize only the sender for a one-to-one message intent.
let handle = INPersonHandle(value: senderId, type: .unknown)
let sender = try INPerson(personHandle: handle,
nameComponents: nil,
displayName: senderName,
image: INImage(imageData: Data(contentsOf: url)),
image: INImage(imageData: Data(contentsOf: mediaFile.url)),
contactIdentifier: nil,
customIdentifier: nil)
+1 -1
View File
@@ -79,7 +79,6 @@ targets:
- path: ../../ElementX/Sources/Services/Media
- path: ../../ElementX/Sources/Services/Background/BackgroundTaskServiceProtocol.swift
- path: ../../ElementX/Sources/Services/Background/BackgroundTaskProtocol.swift
- path: ../../ElementX/Sources/Services/Cache/FileCache.swift
- path: ../../ElementX/Sources/Other/Logging
- path: ../../ElementX/Sources/Other/Extensions/Task.swift
- path: ../../ElementX/Sources/Other/Extensions/FileManager.swift
@@ -87,5 +86,6 @@ targets:
- path: ../../ElementX/Sources/Other/Extensions/Bundle.swift
- path: ../../ElementX/Sources/Other/Extensions/Date.swift
- path: ../../ElementX/Sources/Other/Extensions/ImageCache.swift
- path: ../../ElementX/Sources/Other/Extensions/UTType.swift
- path: ../../ElementX/Sources/Other/AvatarSize.swift
- path: ../../ElementX/Sources/Other/InfoPlistReader.swift