mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Fixed pattern wallpapers not showing in other accounts
This commit is contained in:
parent
938fc01859
commit
dffa9facf4
@ -474,7 +474,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode {
|
|||||||
case let .file(file, _):
|
case let .file(file, _):
|
||||||
let representations: [ImageRepresentationWithReference] = file.previewRepresentations.map({ ImageRepresentationWithReference(representation: $0, reference: AnyMediaReference.message(message: MessageReference(message), media: file).resourceReference($0.resource)) })
|
let representations: [ImageRepresentationWithReference] = file.previewRepresentations.map({ ImageRepresentationWithReference(representation: $0, reference: AnyMediaReference.message(message: MessageReference(message), media: file).resourceReference($0.resource)) })
|
||||||
if file.mimeType == "image/png" {
|
if file.mimeType == "image/png" {
|
||||||
return patternWallpaperImage(account: context.account, representations: representations, mode: .thumbnail)
|
return patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: representations, mode: .thumbnail)
|
||||||
} else {
|
} else {
|
||||||
return wallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, fileReference: FileMediaReference.message(message: MessageReference(message), media: file), representations: representations, alwaysShowThumbnailFirst: false, thumbnail: true, autoFetchFullSize: true)
|
return wallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, fileReference: FileMediaReference.message(message: MessageReference(message), media: file), representations: representations, alwaysShowThumbnailFirst: false, thumbnail: true, autoFetchFullSize: true)
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ public func fetchVideoLibraryMediaResource(postbox: Postbox, resource: VideoLibr
|
|||||||
if let result = next as? TGMediaVideoConversionResult {
|
if let result = next as? TGMediaVideoConversionResult {
|
||||||
var value = stat()
|
var value = stat()
|
||||||
if stat(result.fileURL.path, &value) == 0 {
|
if stat(result.fileURL.path, &value) == 0 {
|
||||||
if config.remuxToFMp4 {
|
if false && config.remuxToFMp4 {
|
||||||
let tempFile = TempBox.shared.tempFile(fileName: "video.mp4")
|
let tempFile = TempBox.shared.tempFile(fileName: "video.mp4")
|
||||||
if false && FFMpegRemuxer.remux(result.fileURL.path, to: tempFile.path) {
|
if FFMpegRemuxer.remux(result.fileURL.path, to: tempFile.path) {
|
||||||
let _ = try? FileManager.default.removeItem(atPath: result.fileURL.path)
|
let _ = try? FileManager.default.removeItem(atPath: result.fileURL.path)
|
||||||
subscriber.putNext(.moveTempFile(file: tempFile))
|
subscriber.putNext(.moveTempFile(file: tempFile))
|
||||||
} else {
|
} else {
|
||||||
@ -228,9 +228,9 @@ func fetchLocalFileVideoMediaResource(postbox: Postbox, resource: LocalFileVideo
|
|||||||
if let result = next as? TGMediaVideoConversionResult {
|
if let result = next as? TGMediaVideoConversionResult {
|
||||||
var value = stat()
|
var value = stat()
|
||||||
if stat(result.fileURL.path, &value) == 0 {
|
if stat(result.fileURL.path, &value) == 0 {
|
||||||
if config.remuxToFMp4 {
|
if false && config.remuxToFMp4 {
|
||||||
let tempFile = TempBox.shared.tempFile(fileName: "video.mp4")
|
let tempFile = TempBox.shared.tempFile(fileName: "video.mp4")
|
||||||
if false && FFMpegRemuxer.remux(result.fileURL.path, to: tempFile.path) {
|
if FFMpegRemuxer.remux(result.fileURL.path, to: tempFile.path) {
|
||||||
let _ = try? FileManager.default.removeItem(atPath: result.fileURL.path)
|
let _ = try? FileManager.default.removeItem(atPath: result.fileURL.path)
|
||||||
subscriber.putNext(.moveTempFile(file: tempFile))
|
subscriber.putNext(.moveTempFile(file: tempFile))
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,7 +121,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
self.backgroundNode.backgroundColor = patternColor
|
self.backgroundNode.backgroundColor = patternColor
|
||||||
self.color = patternColor
|
self.color = patternColor
|
||||||
imageSignal = patternWallpaperImage(account: context.account, representations: convertedRepresentations, mode: .thumbnail, autoFetchFullSize: true)
|
imageSignal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .thumbnail, autoFetchFullSize: true)
|
||||||
} else {
|
} else {
|
||||||
self.backgroundNode.isHidden = true
|
self.backgroundNode.isHidden = true
|
||||||
|
|
||||||
|
@ -457,10 +457,9 @@ final class ThemeGridController: ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mode.contains(.blur) {
|
if mode.contains(.blur) {
|
||||||
let _ = self.context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: {
|
let representation = CachedBlurredWallpaperRepresentation()
|
||||||
apply()
|
let _ = self.context.account.postbox.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true).start()
|
||||||
})
|
let _ = self.context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true).start(completed: {
|
||||||
let _ = self.context.account.postbox.mediaBox.cachedResourceRepresentation(resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: {
|
|
||||||
apply()
|
apply()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -382,8 +382,11 @@ class WallpaperGalleryController: ViewController {
|
|||||||
self?.dismiss(forceAway: true)
|
self?.dismiss(forceAway: true)
|
||||||
})
|
})
|
||||||
|
|
||||||
if case .wallpaper = strongSelf.source {
|
switch strongSelf.source {
|
||||||
let _ = saveWallpaper(account: strongSelf.context.account, wallpaper: wallpaper).start()
|
case .wallpaper, .slug:
|
||||||
|
let _ = saveWallpaper(account: strongSelf.context.account, wallpaper: wallpaper).start()
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
let _ = installWallpaper(account: strongSelf.context.account, wallpaper: wallpaper).start()
|
let _ = installWallpaper(account: strongSelf.context.account, wallpaper: wallpaper).start()
|
||||||
}
|
}
|
||||||
@ -391,18 +394,33 @@ class WallpaperGalleryController: ViewController {
|
|||||||
let applyWallpaper: (TelegramWallpaper) -> Void = { wallpaper in
|
let applyWallpaper: (TelegramWallpaper) -> Void = { wallpaper in
|
||||||
if options.contains(.blur) {
|
if options.contains(.blur) {
|
||||||
if let resource = resource {
|
if let resource = resource {
|
||||||
let _ = strongSelf.context.account.postbox.mediaBox.cachedResourceRepresentation(resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: {
|
let representation = CachedBlurredWallpaperRepresentation()
|
||||||
|
let _ = strongSelf.context.account.postbox.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true).start()
|
||||||
|
|
||||||
|
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||||
|
strongSelf.context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data)
|
||||||
|
let _ = strongSelf.context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true).start(completed: {
|
||||||
|
completion(wallpaper)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if case let .file(file) = wallpaper {
|
||||||
|
if file.isPattern, let color = file.settings.color, let intensity = file.settings.intensity {
|
||||||
|
let representation = CachedPatternWallpaperRepresentation(color: color, intensity: intensity)
|
||||||
|
let _ = strongSelf.context.account.postbox.mediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true).start()
|
||||||
|
|
||||||
|
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(file.file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||||
|
strongSelf.context.sharedContext.accountManager.mediaBox.storeResourceData(file.file.resource.id, data: data)
|
||||||
|
let _ = strongSelf.context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true).start(completed: {
|
||||||
|
completion(wallpaper)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(file.file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||||
|
strongSelf.context.sharedContext.accountManager.mediaBox.storeResourceData(file.file.resource.id, data: data)
|
||||||
completion(wallpaper)
|
completion(wallpaper)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if case let .file(file) = wallpaper, file.isPattern, let color = file.settings.color, let intensity = file.settings.intensity {
|
completion(wallpaper)
|
||||||
let _ = strongSelf.context.account.postbox.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, intensity: intensity), complete: true, fetch: true).start(completed: {
|
|
||||||
completion(wallpaper)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
completion(wallpaper)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
|
|||||||
|
|
||||||
self.colorPreview = self.arguments.colorPreview
|
self.colorPreview = self.arguments.colorPreview
|
||||||
|
|
||||||
signal = patternWallpaperImage(account: context.account, representations: convertedRepresentations, mode: self.arguments.colorPreview ? .fastScreen : .screen, autoFetchFullSize: true)
|
signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: self.arguments.colorPreview ? .fastScreen : .screen, autoFetchFullSize: true)
|
||||||
colorSignal = chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: context.account.postbox.mediaBox)
|
colorSignal = chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: context.account.postbox.mediaBox)
|
||||||
|
|
||||||
isBlurrable = false
|
isBlurrable = false
|
||||||
|
@ -11,15 +11,18 @@ private func wallpaperDatas(account: Account, accountManager: AccountManager, fi
|
|||||||
let maybeFullSize: Signal<MediaResourceData, NoError>
|
let maybeFullSize: Signal<MediaResourceData, NoError>
|
||||||
if thumbnail, let file = fileReference?.media {
|
if thumbnail, let file = fileReference?.media {
|
||||||
maybeFullSize = combineLatest(accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: false, attemptSynchronously: synchronousLoad), account.postbox.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: false, attemptSynchronously: synchronousLoad))
|
maybeFullSize = combineLatest(accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: false, attemptSynchronously: synchronousLoad), account.postbox.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: false, attemptSynchronously: synchronousLoad))
|
||||||
|> mapToSignal { meybeSharedData, maybeData -> Signal<MediaResourceData, NoError> in
|
|> mapToSignal { maybeSharedData, maybeData -> Signal<MediaResourceData, NoError> in
|
||||||
if meybeSharedData.complete {
|
if maybeSharedData.complete {
|
||||||
return .single(meybeSharedData)
|
return .single(maybeSharedData)
|
||||||
} else if maybeData.complete {
|
} else if maybeData.complete {
|
||||||
return .single(maybeData)
|
return .single(maybeData)
|
||||||
} else {
|
} else {
|
||||||
return account.postbox.mediaBox.resourceData(file.resource, attemptSynchronously: synchronousLoad)
|
return combineLatest(accountManager.mediaBox.resourceData(file.resource), account.postbox.mediaBox.resourceData(file.resource))
|
||||||
|> mapToSignal { maybeData -> Signal<MediaResourceData, NoError> in
|
|> mapToSignal { maybeSharedData, maybeData -> Signal<MediaResourceData, NoError> in
|
||||||
if maybeData.complete {
|
if maybeSharedData.complete {
|
||||||
|
return accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: true)
|
||||||
|
}
|
||||||
|
else if maybeData.complete {
|
||||||
return account.postbox.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: true)
|
return account.postbox.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: false, fetch: true)
|
||||||
} else {
|
} else {
|
||||||
return .single(maybeData)
|
return .single(maybeData)
|
||||||
@ -275,7 +278,7 @@ enum PatternWallpaperDrawMode {
|
|||||||
case screen
|
case screen
|
||||||
}
|
}
|
||||||
|
|
||||||
private func patternWallpaperDatas(account: Account, representations: [ImageRepresentationWithReference], mode: PatternWallpaperDrawMode, autoFetchFullSize: Bool = false) -> Signal<(Data?, Data?, Bool), NoError> {
|
private func patternWallpaperDatas(account: Account, accountManager: AccountManager, representations: [ImageRepresentationWithReference], mode: PatternWallpaperDrawMode, autoFetchFullSize: Bool = false) -> Signal<(Data?, Data?, Bool), NoError> {
|
||||||
if let smallestRepresentation = smallestImageRepresentation(representations.map({ $0.representation })), let largestRepresentation = largestImageRepresentation(representations.map({ $0.representation })), let smallestIndex = representations.index(where: { $0.representation == smallestRepresentation }), let largestIndex = representations.index(where: { $0.representation == largestRepresentation }) {
|
if let smallestRepresentation = smallestImageRepresentation(representations.map({ $0.representation })), let largestRepresentation = largestImageRepresentation(representations.map({ $0.representation })), let smallestIndex = representations.index(where: { $0.representation == smallestRepresentation }), let largestIndex = representations.index(where: { $0.representation == largestRepresentation }) {
|
||||||
|
|
||||||
let size: CGSize?
|
let size: CGSize?
|
||||||
@ -287,12 +290,15 @@ private func patternWallpaperDatas(account: Account, representations: [ImageRepr
|
|||||||
default:
|
default:
|
||||||
size = nil
|
size = nil
|
||||||
}
|
}
|
||||||
let maybeFullSize = account.postbox.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: false)
|
let maybeFullSize = combineLatest(accountManager.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: false), account.postbox.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: false))
|
||||||
|
|
||||||
let signal = maybeFullSize
|
let signal = maybeFullSize
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> mapToSignal { maybeData -> Signal<(Data?, Data?, Bool), NoError> in
|
|> mapToSignal { maybeSharedData, maybeData -> Signal<(Data?, Data?, Bool), NoError> in
|
||||||
if maybeData.complete {
|
if maybeSharedData.complete {
|
||||||
|
let loadedData: Data? = try? Data(contentsOf: URL(fileURLWithPath: maybeSharedData.path), options: [])
|
||||||
|
return .single((nil, loadedData, true))
|
||||||
|
} else if maybeData.complete {
|
||||||
let loadedData: Data? = try? Data(contentsOf: URL(fileURLWithPath: maybeData.path), options: [])
|
let loadedData: Data? = try? Data(contentsOf: URL(fileURLWithPath: maybeData.path), options: [])
|
||||||
return .single((nil, loadedData, true))
|
return .single((nil, loadedData, true))
|
||||||
} else {
|
} else {
|
||||||
@ -303,6 +309,11 @@ private func patternWallpaperDatas(account: Account, representations: [ImageRepr
|
|||||||
let fetchedDisposable = fetchedThumbnail.start()
|
let fetchedDisposable = fetchedThumbnail.start()
|
||||||
let thumbnailDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
let thumbnailDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
||||||
subscriber.putNext(next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []))
|
subscriber.putNext(next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []))
|
||||||
|
|
||||||
|
if next.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: next.path), options: .mappedRead) {
|
||||||
|
accountManager.mediaBox.storeResourceData(representations[smallestIndex].representation.resource.id, data: data)
|
||||||
|
let _ = accountManager.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start()
|
||||||
|
}
|
||||||
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||||
|
|
||||||
return ActionDisposable {
|
return ActionDisposable {
|
||||||
@ -315,6 +326,11 @@ private func patternWallpaperDatas(account: Account, representations: [ImageRepr
|
|||||||
let fetchedFullSizeDisposable = fetchedFullSize.start()
|
let fetchedFullSizeDisposable = fetchedFullSize.start()
|
||||||
let fullSizeDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
let fullSizeDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
||||||
subscriber.putNext((next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []), next.complete))
|
subscriber.putNext((next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []), next.complete))
|
||||||
|
|
||||||
|
if next.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: next.path), options: .mappedRead) {
|
||||||
|
accountManager.mediaBox.storeResourceData(representations[largestIndex].representation.resource.id, data: data)
|
||||||
|
let _ = accountManager.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start()
|
||||||
|
}
|
||||||
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||||
|
|
||||||
return ActionDisposable {
|
return ActionDisposable {
|
||||||
@ -337,9 +353,8 @@ private func patternWallpaperDatas(account: Account, representations: [ImageRepr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func patternWallpaperImage(account: Account, representations: [ImageRepresentationWithReference], mode: PatternWallpaperDrawMode, autoFetchFullSize: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
func patternWallpaperImage(account: Account, accountManager: AccountManager, representations: [ImageRepresentationWithReference], mode: PatternWallpaperDrawMode, autoFetchFullSize: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||||
|
return patternWallpaperDatas(account: account, accountManager: accountManager, representations: representations, mode: mode, autoFetchFullSize: autoFetchFullSize)
|
||||||
return patternWallpaperDatas(account: account, representations: representations, mode: mode, autoFetchFullSize: autoFetchFullSize)
|
|
||||||
|> mapToSignal { (thumbnailData, fullSizeData, fullSizeComplete) in
|
|> mapToSignal { (thumbnailData, fullSizeData, fullSizeComplete) in
|
||||||
return patternWallpaperImageInternal(thumbnailData: thumbnailData, fullSizeData: fullSizeData, fullSizeComplete: fullSizeComplete, mode: mode)
|
return patternWallpaperImageInternal(thumbnailData: thumbnailData, fullSizeData: fullSizeData, fullSizeComplete: fullSizeComplete, mode: mode)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user