Custom copy for notifications that contain mentions (#2050)

This commit is contained in:
Mauro
2023-11-09 19:12:11 +01:00
committed by GitHub
parent 019ca625ab
commit a4bc7b8e36
21 changed files with 139 additions and 90 deletions
@@ -37,8 +37,14 @@ class MediaFileHandleProxy {
}
/// The media file's location on disk.
var url: URL {
URL(filePath: handle.path())
var url: URL? {
do {
let path = try handle.path()
return URL(filePath: path)
} catch {
MXLog.error("URL is missing for media file handle: \(error)")
return nil
}
}
}
@@ -60,6 +66,10 @@ extension MediaFileHandleProxy: Hashable {
///
/// This type allows for mocking but doesn't provide the automatic clean-up mechanism provided by the SDK.
private class UnmanagedMediaFileHandle: MediaFileHandleProtocol {
func persist(path: String) throws -> Bool {
false
}
let url: URL
init(url: URL) {
@@ -48,7 +48,7 @@ actor MediaLoader: MediaLoaderProtocol {
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
let result = try await Task.dispatch(on: clientQueue) {
try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream", tempDir: nil)
try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream", useCache: true, tempDir: nil)
}
return MediaFileHandleProxy(handle: result)
@@ -60,6 +60,10 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
var isNoisy: Bool {
notificationItem.isNoisy ?? false
}
var hasMention: Bool {
notificationItem.hasMention ?? false
}
var senderAvatarMediaSource: MediaSourceProxy? {
if let senderAvatarURLString = notificationItem.senderInfo.avatarUrl,
@@ -114,4 +118,6 @@ struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
var notificationIdentifier: String { "" }
var roomJoinedMembers: Int { 0 }
var hasMention: Bool { false }
}
@@ -44,6 +44,8 @@ protocol NotificationItemProxyProtocol {
var isRoomDirect: Bool { get }
var isNoisy: Bool { get }
var hasMention: Bool { get }
}
extension NotificationItemProxyProtocol {
@@ -182,7 +182,7 @@ extension BackupState {
var keyBackupState: SecureBackupKeyBackupState {
switch self {
case .unknown:
return .unknown
return .disabled
case .creating:
return .enabling
case .enabling:
@@ -195,8 +195,6 @@ extension BackupState {
return .enabled
case .disabling:
return .disabling
case .disabled:
return .disabled
}
}
}
@@ -18,6 +18,7 @@ import Foundation
enum VoiceMessageMediaManagerError: Error {
case unsupportedMimeTye
case missingURL
}
private final class VoiceMessageConversionRequest {
@@ -76,8 +77,11 @@ class VoiceMessageMediaManager: VoiceMessageMediaManagerProtocol {
}
// Convert from ogg
let convertedFileURL = URL.temporaryDirectory.appendingPathComponent(fileHandle.url.deletingPathExtension().lastPathComponent).appendingPathExtension(AudioConverterPreferredFileExtension.mpeg4aac.rawValue)
try audioConverter.convertToMPEG4AAC(sourceURL: fileHandle.url, destinationURL: convertedFileURL)
guard let url = fileHandle.url else {
throw VoiceMessageMediaManagerError.missingURL
}
let convertedFileURL = URL.temporaryDirectory.appendingPathComponent(url.deletingPathExtension().lastPathComponent).appendingPathExtension(AudioConverterPreferredFileExtension.mpeg4aac.rawValue)
try audioConverter.convertToMPEG4AAC(sourceURL: url, destinationURL: convertedFileURL)
// Cache the file and return the url
let result = voiceMessageCache.cache(mediaSource: source, using: convertedFileURL, move: true)