mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-09 07:41:40 +00:00
Merge commit '78ccc864b9b9259963c485563a7628137bb733de'
This commit is contained in:
commit
3fc1a4fb04
@ -143,7 +143,7 @@ class ThemeSettingsChatPreviewItemNode: ListViewItemNode {
|
||||
return { item, params, neighbors in
|
||||
var updatedBackgroundSignal: Signal<(UIImage?, Bool)?, NoError>?
|
||||
if currentItem?.wallpaper != item.wallpaper {
|
||||
updatedBackgroundSignal = chatControllerBackgroundImageSignal(wallpaper: item.wallpaper, mediaBox: item.context.sharedContext.accountManager.mediaBox)
|
||||
updatedBackgroundSignal = chatControllerBackgroundImageSignal(wallpaper: item.wallpaper, mediaBox: item.context.sharedContext.accountManager.mediaBox, accountMediaBox: item.context.account.postbox.mediaBox)
|
||||
}
|
||||
|
||||
let insets: UIEdgeInsets
|
||||
|
||||
@ -106,7 +106,7 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
|
||||
|
||||
private var signalBackgroundImageForWallpaper: (TelegramWallpaper, Bool, UIImage)?
|
||||
|
||||
public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, mediaBox: MediaBox) -> Signal<(UIImage?, Bool)?, NoError> {
|
||||
public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, mediaBox: MediaBox, accountMediaBox: MediaBox) -> Signal<(UIImage?, Bool)?, NoError> {
|
||||
var backgroundImage: UIImage?
|
||||
if wallpaper == signalBackgroundImageForWallpaper?.0, (wallpaper.settings?.blur ?? false) == signalBackgroundImageForWallpaper?.1, let image = signalBackgroundImageForWallpaper?.2 {
|
||||
return .single((image, true))
|
||||
@ -175,7 +175,16 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
}
|
||||
case let .file(file):
|
||||
if wallpaper.isPattern, let color = file.settings.color, let intensity = file.settings.intensity {
|
||||
return mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: true)
|
||||
let representation = CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation)
|
||||
|
||||
let effectiveMediaBox: MediaBox
|
||||
if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) {
|
||||
effectiveMediaBox = mediaBox
|
||||
} else {
|
||||
effectiveMediaBox = accountMediaBox
|
||||
}
|
||||
|
||||
return effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true)
|
||||
|> take(1)
|
||||
|> mapToSignal { data -> Signal<(UIImage?, Bool)?, NoError> in
|
||||
if data.complete {
|
||||
@ -205,7 +214,7 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
}
|
||||
})
|
||||
|
||||
return .single((interrimImage, false)) |> then(mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false)
|
||||
return .single((interrimImage, false)) |> then(effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true, attemptSynchronously: false)
|
||||
|> map { data -> (UIImage?, Bool)? in
|
||||
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
||||
})
|
||||
@ -216,7 +225,16 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
}
|
||||
} else {
|
||||
if file.settings.blur {
|
||||
return mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true, attemptSynchronously: true)
|
||||
let representation = CachedBlurredWallpaperRepresentation()
|
||||
|
||||
let effectiveMediaBox: MediaBox
|
||||
if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) {
|
||||
effectiveMediaBox = mediaBox
|
||||
} else {
|
||||
effectiveMediaBox = accountMediaBox
|
||||
}
|
||||
|
||||
return effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true)
|
||||
|> map { data -> (UIImage?, Bool)? in
|
||||
if data.complete {
|
||||
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
||||
@ -227,7 +245,14 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
|> afterNext { image in
|
||||
cacheWallpaper(image?.0)
|
||||
}
|
||||
} else if let path = mediaBox.completedResourcePath(file.file.resource) {
|
||||
} else {
|
||||
var path: String?
|
||||
if let maybePath = mediaBox.completedResourcePath(file.file.resource) {
|
||||
path = maybePath
|
||||
} else if let maybePath = accountMediaBox.completedResourcePath(file.file.resource) {
|
||||
path = maybePath
|
||||
}
|
||||
if let path = path {
|
||||
return .single((UIImage(contentsOfFile: path)?.precomposed(), true))
|
||||
|> afterNext { image in
|
||||
cacheWallpaper(image?.0)
|
||||
@ -236,5 +261,6 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return .complete()
|
||||
}
|
||||
|
||||
@ -26,11 +26,11 @@ public final class CachedWallpaper: PostboxCoding {
|
||||
|
||||
private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 10000, highWaterItemCount: 20000)
|
||||
|
||||
public func cachedWallpaper(account: Account, slug: String, settings: WallpaperSettings?) -> Signal<CachedWallpaper?, NoError> {
|
||||
public func cachedWallpaper(account: Account, slug: String, settings: WallpaperSettings?, update: Bool = false) -> Signal<CachedWallpaper?, NoError> {
|
||||
return account.postbox.transaction { transaction -> Signal<CachedWallpaper?, NoError> in
|
||||
let key = ValueBoxKey(length: 8)
|
||||
key.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue))
|
||||
if let entry = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, key: key)) as? CachedWallpaper {
|
||||
if !update, let entry = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, key: key)) as? CachedWallpaper {
|
||||
if let settings = settings {
|
||||
return .single(CachedWallpaper(wallpaper: entry.wallpaper.withUpdatedSettings(settings)))
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user