Various fixes

This commit is contained in:
Ilya Laktyushin 2023-12-20 18:33:19 +04:00
parent 90a1e9b688
commit 2f0070cccb
2 changed files with 36 additions and 8 deletions

View File

@ -11,26 +11,28 @@ import WallpaperBackgroundNode
public final class DrawingWallpaperRenderer {
private let context: AccountContext
private let customWallpaper: TelegramWallpaper?
private let customDayWallpaper: TelegramWallpaper?
private let customNightWallpaper: TelegramWallpaper?
private let wallpaperBackgroundNode: WallpaperBackgroundNode
private let darkWallpaperBackgroundNode: WallpaperBackgroundNode
public init (context: AccountContext, customWallpaper: TelegramWallpaper?) {
public init (context: AccountContext, customDayWallpaper: TelegramWallpaper?, customNightWallpaper: TelegramWallpaper?) {
self.context = context
self.customWallpaper = customWallpaper
self.customDayWallpaper = customDayWallpaper
self.customNightWallpaper = customNightWallpaper
self.wallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false)
self.wallpaperBackgroundNode.displaysAsynchronously = false
let wallpaper = self.customWallpaper ?? context.sharedContext.currentPresentationData.with { $0 }.chatWallpaper
let wallpaper = self.customDayWallpaper ?? context.sharedContext.currentPresentationData.with { $0 }.chatWallpaper
self.wallpaperBackgroundNode.update(wallpaper: wallpaper, animated: false)
self.darkWallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false)
self.darkWallpaperBackgroundNode.displaysAsynchronously = false
let darkTheme = defaultDarkColorPresentationTheme
let darkWallpaper = darkTheme.chat.defaultWallpaper
let darkWallpaper = self.customNightWallpaper ?? darkTheme.chat.defaultWallpaper
self.darkWallpaperBackgroundNode.update(wallpaper: darkWallpaper, animated: false)
}
@ -39,7 +41,7 @@ public final class DrawingWallpaperRenderer {
let resultSize = CGSize(width: 1080, height: 1920)
self.generate(view: self.wallpaperBackgroundNode.view) { dayImage in
if self.customWallpaper != nil {
if self.customDayWallpaper != nil && self.customNightWallpaper == nil {
completion(resultSize, dayImage, nil, nil)
} else {
Queue.mainQueue().justDispatch {

View File

@ -136,10 +136,36 @@ public func getChatWallpaperImage(context: AccountContext, messageId: EngineMess
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
|> mapToSignal { wallpaper -> Signal<(TelegramWallpaper?, TelegramWallpaper?), NoError> in
if let wallpaper, case let .emoticon(emoticon) = wallpaper {
return context.engine.themes.getChatThemes(accountManager: context.sharedContext.accountManager)
|> map { themes -> (TelegramWallpaper?, TelegramWallpaper?) in
if let theme = themes.first(where: { $0.emoticon?.strippedEmoji == emoticon.strippedEmoji }) {
if let dayMatch = theme.settings?.first(where: { $0.baseTheme == .classic || $0.baseTheme == .day }) {
if let dayWallpaper = dayMatch.wallpaper {
var nightWallpaper: TelegramWallpaper?
if let nightMatch = theme.settings?.first(where: { $0.baseTheme == .night || $0.baseTheme == .tinted }) {
nightWallpaper = nightMatch.wallpaper
}
return (dayWallpaper, nightWallpaper)
} else {
return (nil, nil)
}
} else {
return (nil, nil)
}
} else {
return (nil, nil)
}
}
} else {
return .single((wallpaper, nil))
}
}
|> mapToSignal { customDayWallpaper, customNightWallpaper -> Signal<(CGSize, UIImage?, UIImage?), NoError> in
return Signal { subscriber in
Queue.mainQueue().async {
let wallpaperRenderer = DrawingWallpaperRenderer(context: context, customWallpaper: customWallpaper)
let wallpaperRenderer = DrawingWallpaperRenderer(context: context, customDayWallpaper: customDayWallpaper, customNightWallpaper: customNightWallpaper)
wallpaperRenderer.render { size, image, darkImage, mediaRect in
subscriber.putNext((size, image, darkImage))
subscriber.putCompletion()