mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Using thumbnails for notification icons (#2142)
This commit is contained in:
@@ -117,7 +117,7 @@ extension UNMutableNotificationContent {
|
|||||||
var fetchedImage: INImage?
|
var fetchedImage: INImage?
|
||||||
let image: INImage
|
let image: INImage
|
||||||
if let mediaSource = icon.mediaSource {
|
if let mediaSource = icon.mediaSource {
|
||||||
switch await mediaProvider?.loadImageDataFromSource(mediaSource) {
|
switch await mediaProvider?.loadThumbnailForSource(source: mediaSource, size: .init(width: 100, height: 100)) {
|
||||||
case .success(let data):
|
case .success(let data):
|
||||||
fetchedImage = INImage(imageData: data)
|
fetchedImage = INImage(imageData: data)
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
|
|||||||
@@ -104,6 +104,18 @@ struct MediaProvider: MediaProviderProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Thumbnail
|
||||||
|
|
||||||
|
func loadThumbnailForSource(source: MediaSourceProxy, size: CGSize) async -> Result<Data, MediaProviderError> {
|
||||||
|
do {
|
||||||
|
let thumbnailData = try await mediaLoader.loadMediaThumbnailForSource(source, width: UInt(size.width), height: UInt(size.height))
|
||||||
|
return .success(thumbnailData)
|
||||||
|
} catch {
|
||||||
|
MXLog.error("Failed retrieving image with error: \(error)")
|
||||||
|
return .failure(.failedRetrievingThumbnail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private func cacheKeyForURL(_ url: URL, size: CGSize?) -> String {
|
private func cacheKeyForURL(_ url: URL, size: CGSize?) -> String {
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ enum MediaProviderError: Error {
|
|||||||
case failedRetrievingImage
|
case failedRetrievingImage
|
||||||
case failedRetrievingFile
|
case failedRetrievingFile
|
||||||
case invalidImageData
|
case invalidImageData
|
||||||
|
case failedRetrievingThumbnail
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol MediaProviderProtocol: ImageProviderProtocol {
|
protocol MediaProviderProtocol: ImageProviderProtocol {
|
||||||
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError>
|
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError>
|
||||||
|
func loadThumbnailForSource(source: MediaSourceProxy, size: CGSize) async -> Result<Data, MediaProviderError>
|
||||||
}
|
}
|
||||||
|
|
||||||
extension MediaProviderProtocol {
|
extension MediaProviderProtocol {
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
struct MockMediaProvider: MediaProviderProtocol {
|
struct MockMediaProvider: MediaProviderProtocol {
|
||||||
|
func loadThumbnailForSource(source: MediaSourceProxy, size: CGSize) async -> Result<Data, MediaProviderError> {
|
||||||
|
fatalError("Not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func imageFromSource(_ source: MediaSourceProxy?, size: CGSize?) -> UIImage? {
|
func imageFromSource(_ source: MediaSourceProxy?, size: CGSize?) -> UIImage? {
|
||||||
guard source != nil else {
|
guard source != nil else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Fixed a bug that made iOS 17 render avatars sideways in notifications.
|
||||||
Reference in New Issue
Block a user