mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
• Added more details to profile update logs (also added debug logs for updating other users profiles) • Added a delay before killing the app after clearing data to give the libSession logger more time to shutdown (false crash reports) • Removed some emoji encoding which is no longer needed • Fixed a couple of cases where we were trying to access the libSession cache for new accounts before it had been created • Fixed a bug where we could try to render a profile picture for the current user even if it hadn't been downloaded yet (resulting in nothing being rendered) • Fixed a bug where restoring an account would clear the users display picture • Fixed a bug where we wouldn't immediately download the users display picture after restoring an account • Fixed a bug where video attachments weren't getting their metadata extracted correctly (preventing them from being sent correctly) • Fixed a bug where some video formats might not be recognised as video • Fixed a bug preventing emoji reactions in communities • Fixed a bug where portrait images wouldn't crop correctly
99 lines
4.0 KiB
Swift
99 lines
4.0 KiB
Swift
// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import AVFoundation
|
|
import UniformTypeIdentifiers
|
|
|
|
public extension AVURLAsset {
|
|
var maxVideoTrackSize: CGSize {
|
|
var result: CGSize = .zero
|
|
|
|
for track: AVAssetTrack in tracks(withMediaType: .video) {
|
|
let trackSize: CGSize = track.naturalSize
|
|
let transformedSize: CGSize = trackSize.applying(track.preferredTransform)
|
|
result.width = max(result.width, abs(transformedSize.width))
|
|
result.height = max(result.height, abs(transformedSize.height))
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
static func asset(for path: String, utType: UTType?, sourceFilename: String?, using dependencies: Dependencies) -> (asset: AVURLAsset, utType: UTType, cleanup: () -> Void)? {
|
|
if #available(iOS 17.0, *) {
|
|
/// Since `mimeType` can be null we need to try to resolve it to a value
|
|
let finalMimeType: String
|
|
let finalUTType: UTType
|
|
|
|
switch (utType, sourceFilename) {
|
|
case (.none, .none): return nil
|
|
case (.some(let utType), _):
|
|
guard let mimeType: String = utType.sessionMimeType else {
|
|
return nil
|
|
}
|
|
|
|
finalMimeType = mimeType
|
|
finalUTType = utType
|
|
|
|
case (.none, .some(let sourceFilename)):
|
|
guard
|
|
let utType: UTType = UTType(
|
|
sessionFileExtension: URL(fileURLWithPath: sourceFilename).pathExtension
|
|
),
|
|
let mimeType: String = utType.sessionMimeType
|
|
else { return nil }
|
|
|
|
finalMimeType = mimeType
|
|
finalUTType = utType
|
|
}
|
|
|
|
return (
|
|
AVURLAsset(
|
|
url: URL(fileURLWithPath: path),
|
|
options: [AVURLAssetOverrideMIMETypeKey: finalMimeType]
|
|
),
|
|
finalUTType,
|
|
{}
|
|
)
|
|
}
|
|
else {
|
|
/// Since `mimeType` and/or `sourceFilename` can be null we need to try to resolve them both to values
|
|
let finalExtension: String
|
|
let finalUTType: UTType
|
|
|
|
switch (utType, sourceFilename) {
|
|
case (.none, .none): return nil
|
|
case (.none, .some(let sourceFilename)):
|
|
guard
|
|
let utType: UTType = UTType(
|
|
sessionFileExtension: URL(fileURLWithPath: sourceFilename).pathExtension
|
|
),
|
|
let fileExtension: String = utType.sessionFileExtension(sourceFilename: sourceFilename)
|
|
else { return nil }
|
|
|
|
finalExtension = fileExtension
|
|
finalUTType = utType
|
|
|
|
case (.some(let utType), let sourceFilename):
|
|
guard let fileExtension: String = utType.sessionFileExtension(sourceFilename: sourceFilename) else {
|
|
return nil
|
|
}
|
|
|
|
finalExtension = fileExtension
|
|
finalUTType = utType
|
|
}
|
|
|
|
let tmpPath: String = URL(fileURLWithPath: dependencies[singleton: .fileManager].temporaryDirectory)
|
|
.appendingPathComponent(URL(fileURLWithPath: path).lastPathComponent)
|
|
.appendingPathExtension(finalExtension)
|
|
.path
|
|
|
|
try? dependencies[singleton: .fileManager].copyItem(atPath: path, toPath: tmpPath)
|
|
|
|
return (
|
|
AVURLAsset(url: URL(fileURLWithPath: tmpPath), options: nil),
|
|
finalUTType,
|
|
{ [dependencies] in try? dependencies[singleton: .fileManager].removeItem(atPath: tmpPath) }
|
|
)
|
|
}
|
|
}
|
|
}
|