mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Using thumbnails for notification icons (#2142)
This commit is contained in:
parent
7c3ee01a6f
commit
a7c194198d
@ -117,7 +117,7 @@ extension UNMutableNotificationContent {
|
||||
var fetchedImage: INImage?
|
||||
let image: INImage
|
||||
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):
|
||||
fetchedImage = INImage(imageData: data)
|
||||
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
|
||||
|
||||
private func cacheKeyForURL(_ url: URL, size: CGSize?) -> String {
|
||||
|
@ -21,10 +21,12 @@ enum MediaProviderError: Error {
|
||||
case failedRetrievingImage
|
||||
case failedRetrievingFile
|
||||
case invalidImageData
|
||||
case failedRetrievingThumbnail
|
||||
}
|
||||
|
||||
protocol MediaProviderProtocol: ImageProviderProtocol {
|
||||
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError>
|
||||
func loadThumbnailForSource(source: MediaSourceProxy, size: CGSize) async -> Result<Data, MediaProviderError>
|
||||
}
|
||||
|
||||
extension MediaProviderProtocol {
|
||||
|
@ -18,6 +18,10 @@ import Foundation
|
||||
import UIKit
|
||||
|
||||
struct MockMediaProvider: MediaProviderProtocol {
|
||||
func loadThumbnailForSource(source: MediaSourceProxy, size: CGSize) async -> Result<Data, MediaProviderError> {
|
||||
fatalError("Not implemented")
|
||||
}
|
||||
|
||||
func imageFromSource(_ source: MediaSourceProxy?, size: CGSize?) -> UIImage? {
|
||||
guard source != nil else {
|
||||
return nil
|
||||
|
1
changelog.d/2136.bugfix
Normal file
1
changelog.d/2136.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fixed a bug that made iOS 17 render avatars sideways in notifications.
|
Loading…
x
Reference in New Issue
Block a user