Various fixes

This commit is contained in:
Ilya Laktyushin
2023-12-18 17:14:00 +04:00
parent 758016c638
commit 595dfd18c5
11 changed files with 258 additions and 119 deletions

View File

@@ -2,6 +2,8 @@ import Foundation
import UIKit
import AVFoundation
import SwiftSignalKit
import TelegramCore
import AccountContext
extension AVPlayer {
func fadeVolume(from: Float, to: Float, duration: Float, completion: (() -> Void)? = nil) -> SwiftSignalKit.Timer? {
@@ -129,3 +131,21 @@ func getTextureImage(device: MTLDevice, texture: MTLTexture, mirror: Bool = fals
}
return UIImage(cgImage: cgImage)
}
public func getChatWallpaperImage(context: AccountContext, messageId: EngineMessage.Id) -> Signal<(CGSize, UIImage?, UIImage?), NoError> {
return context.account.postbox.transaction { transaction -> TelegramWallpaper? in
return (transaction.getPeerCachedData(peerId: messageId.peerId) as? CachedChannelData)?.wallpaper
}
|> mapToSignal { customWallpaper -> Signal<(CGSize, UIImage?, UIImage?), NoError> in
return Signal { subscriber in
Queue.mainQueue().async {
let wallpaperRenderer = DrawingWallpaperRenderer(context: context, customWallpaper: customWallpaper)
wallpaperRenderer.render { size, image, darkImage in
subscriber.putNext((size, image, darkImage))
subscriber.putCompletion()
}
}
return EmptyDisposable
}
}
}