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
|
return { item, params, neighbors in
|
||||||
var updatedBackgroundSignal: Signal<(UIImage?, Bool)?, NoError>?
|
var updatedBackgroundSignal: Signal<(UIImage?, Bool)?, NoError>?
|
||||||
if currentItem?.wallpaper != item.wallpaper {
|
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
|
let insets: UIEdgeInsets
|
||||||
|
|||||||
@ -106,7 +106,7 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i
|
|||||||
|
|
||||||
private var signalBackgroundImageForWallpaper: (TelegramWallpaper, Bool, UIImage)?
|
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?
|
var backgroundImage: UIImage?
|
||||||
if wallpaper == signalBackgroundImageForWallpaper?.0, (wallpaper.settings?.blur ?? false) == signalBackgroundImageForWallpaper?.1, let image = signalBackgroundImageForWallpaper?.2 {
|
if wallpaper == signalBackgroundImageForWallpaper?.0, (wallpaper.settings?.blur ?? false) == signalBackgroundImageForWallpaper?.1, let image = signalBackgroundImageForWallpaper?.2 {
|
||||||
return .single((image, true))
|
return .single((image, true))
|
||||||
@ -175,7 +175,16 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
|||||||
}
|
}
|
||||||
case let .file(file):
|
case let .file(file):
|
||||||
if wallpaper.isPattern, let color = file.settings.color, let intensity = file.settings.intensity {
|
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)
|
|> take(1)
|
||||||
|> mapToSignal { data -> Signal<(UIImage?, Bool)?, NoError> in
|
|> mapToSignal { data -> Signal<(UIImage?, Bool)?, NoError> in
|
||||||
if data.complete {
|
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
|
|> map { data -> (UIImage?, Bool)? in
|
||||||
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
||||||
})
|
})
|
||||||
@ -216,7 +225,16 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if file.settings.blur {
|
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
|
|> map { data -> (UIImage?, Bool)? in
|
||||||
if data.complete {
|
if data.complete {
|
||||||
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
return (UIImage(contentsOfFile: data.path)?.precomposed(), true)
|
||||||
@ -227,10 +245,18 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me
|
|||||||
|> afterNext { image in
|
|> afterNext { image in
|
||||||
cacheWallpaper(image?.0)
|
cacheWallpaper(image?.0)
|
||||||
}
|
}
|
||||||
} else if let path = mediaBox.completedResourcePath(file.file.resource) {
|
} else {
|
||||||
return .single((UIImage(contentsOfFile: path)?.precomposed(), true))
|
var path: String?
|
||||||
|> afterNext { image in
|
if let maybePath = mediaBox.completedResourcePath(file.file.resource) {
|
||||||
cacheWallpaper(image?.0)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,11 +26,11 @@ public final class CachedWallpaper: PostboxCoding {
|
|||||||
|
|
||||||
private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 10000, highWaterItemCount: 20000)
|
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
|
return account.postbox.transaction { transaction -> Signal<CachedWallpaper?, NoError> in
|
||||||
let key = ValueBoxKey(length: 8)
|
let key = ValueBoxKey(length: 8)
|
||||||
key.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue))
|
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 {
|
if let settings = settings {
|
||||||
return .single(CachedWallpaper(wallpaper: entry.wallpaper.withUpdatedSettings(settings)))
|
return .single(CachedWallpaper(wallpaper: entry.wallpaper.withUpdatedSettings(settings)))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user