diff --git a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift index 00055cedaf..7c0561e3cc 100644 --- a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift +++ b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift @@ -126,7 +126,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { } let imageSignal: Signal<(TransformImageArguments) -> DrawingContext?, NoError> - if file.isPattern { + if wallpaper.isPattern { self.backgroundNode.isHidden = false var patternColors: [UIColor] = [] diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 7158f04941..5715fd93b8 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -382,7 +382,7 @@ final class ThemeAccentColorController: ViewController { guard let wallpaper = wallpaper else { return } - if case let .file(file) = wallpaper, file.isPattern { + if case let .file(file) = wallpaper, wallpaper.isPattern { var patternColor = UIColor(rgb: 0xd6e2ee, alpha: 0.4) var bottomColor: UIColor? if let color = file.settings.color { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift index 26275984bf..26ba04aae7 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift @@ -211,7 +211,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate case .image, .builtin: return true case let .file(file): - return !file.isPattern + return !self.wallpaper.isPattern default: return false } @@ -505,7 +505,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate let patternArguments = PatternWallpaperArguments(colors: calcPatternColors(for: state), rotation: wallpaper.settings?.rotation ?? 0, preview: state.preview) var wallpaperApply: (() -> Void)? - if let strongSelf = self, case let .file(file) = wallpaper, file.isPattern, let (layout, _, _) = strongSelf.validLayout { + if let strongSelf = self, wallpaper.isPattern, let (layout, _, _) = strongSelf.validLayout { let makeImageLayout = strongSelf.signalBackgroundNode.asyncLayout() wallpaperApply = makeImageLayout(TransformImageArguments(corners: ImageCorners(), imageSize: wallpaper.dimensions ?? layout.size, boundingSize: layout.size, intrinsicInsets: UIEdgeInsets(), custom: patternArguments)) } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift index 4fcb1f94fd..75476d20eb 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift @@ -383,7 +383,7 @@ final class ThemeGridControllerNode: ASDisplayNode { } for wallpaper in sortedWallpapers { - if case let .file(file) = wallpaper, deletedWallpaperSlugs.contains(file.slug) || (file.isPattern && file.settings.color == nil) { + if case let .file(file) = wallpaper, deletedWallpaperSlugs.contains(file.slug) || (wallpaper.isPattern && file.settings.color == nil) { continue } let selected = presentationData.chatWallpaper.isBasicallyEqual(to: wallpaper) diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift index b3938cb1b9..88ce65179a 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift @@ -235,7 +235,7 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { let signal: Signal<(TransformImageArguments) -> DrawingContext?, NoError> let fileReference = FileMediaReference.standalone(media: file.file) - if file.isPattern { + if wallpaper.isPattern { signal = patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: false) } else if strongSelf.instantChatBackgroundNode.image == nil { signal = wallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, fileReference: fileReference, representations: convertedRepresentations, alwaysShowThumbnailFirst: false, autoFetchFullSize: false) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift index 0b1cac8fb9..5faa7048b9 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift @@ -772,8 +772,7 @@ final class WallpaperColorPanelNode: ASDisplayNode { let secondColor: UIColor if updated.simpleGradientGeneration { - var colorHsb = color.hsb - + var colorHsb = color.hsb if color.hsb.2 > 0.5 { secondColor = UIColor(hue: colorHsb.0, saturation: colorHsb.1, brightness: max(0.28, color.hsb.2 - 0.3), alpha: 1.0) } else { diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 9eb5fcf49b..d9bef27d75 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -106,7 +106,7 @@ private func updatedFileWallpaper(wallpaper: TelegramWallpaper, firstColor: UICo } private func updatedFileWallpaper(id: Int64? = nil, accessHash: Int64? = nil, slug: String, file: TelegramMediaFile, firstColor: UIColor?, secondColor: UIColor?, intensity: Int32?, rotation: Int32?) -> TelegramWallpaper { - let isPattern = file.mimeType == "image/png" + let isPattern = ["image/png", "image/svg+xml"].contains(file.mimeType) var firstColorValue: UInt32? var secondColorValue: UInt32? var intensityValue: Int32? @@ -429,7 +429,7 @@ public class WallpaperGalleryController: ViewController { } } } else if case let .file(file) = wallpaper, let resource = resource { - if file.isPattern, let color = file.settings.color, let intensity = file.settings.intensity { + if wallpaper.isPattern, let color = file.settings.color, let intensity = file.settings.intensity { let representation = CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation) var data: Data? @@ -577,7 +577,7 @@ public class WallpaperGalleryController: ViewController { if let entryColor = entryColor { if let pattern = pattern, case let .file(file) = pattern { let newSettings = WallpaperSettings(blur: file.settings.blur, motion: file.settings.motion, color: entryColor, intensity: intensity) - let newWallpaper = TelegramWallpaper.file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: file.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: newSettings) + let newWallpaper = TelegramWallpaper.file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: pattern.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: newSettings) updatedEntries.append(.wallpaper(newWallpaper, nil)) } else { let newWallpaper = TelegramWallpaper.color(entryColor) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index a845180146..535d4aed3a 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -267,7 +267,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { } convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource), reference: reference(for: file.file.resource, media: file.file, message: message))) - if file.isPattern { + if wallpaper.isPattern { var patternColors: [UIColor] = [] var patternColor = UIColor(rgb: 0xd6e2ee, alpha: 0.5) var patternIntensity: CGFloat = 0.5 @@ -751,7 +751,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { case .gradient: motionAlpha = 1.0 case let .file(file): - if file.isPattern { + if wallpaper.isPattern { motionAlpha = 1.0 if self.arguments.isColorsList { patternAlpha = 1.0 diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift index 54d00f91de..d811ce42ac 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift @@ -84,7 +84,7 @@ final class WallpaperPatternPanelNode: ASDisplayNode { self.disposable = ((telegramWallpapers(postbox: context.account.postbox, network: context.account.network) |> map { wallpapers in return wallpapers.filter { wallpaper in - if case let .file(file) = wallpaper, file.isPattern, file.file.mimeType != "image/webp" { + if case let .file(file) = wallpaper, wallpaper.isPattern, file.file.mimeType != "image/webp" { return true } else { return false @@ -128,6 +128,7 @@ final class WallpaperPatternPanelNode: ASDisplayNode { } func updateWallpapers() { + return guard let subnodes = self.scrollNode.subnodes else { return } @@ -151,7 +152,7 @@ final class WallpaperPatternPanelNode: ASDisplayNode { var updatedWallpaper = wallpaper if case let .file(file) = updatedWallpaper { let settings = WallpaperSettings(color: backgroundColors.0.rgb, bottomColor: backgroundColors.1.flatMap { $0.rgb }, intensity: 100) - updatedWallpaper = .file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: file.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: settings) + updatedWallpaper = .file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: updatedWallpaper.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: settings) } var selected = false diff --git a/submodules/Svg/Sources/SVGKit/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m b/submodules/Svg/Sources/SVGKit/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m index bf77521b97..9cdd690fcb 100644 --- a/submodules/Svg/Sources/SVGKit/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m +++ b/submodules/Svg/Sources/SVGKit/Source/DOM classes/SVG-DOM/SVGHelperUtilities.m @@ -580,7 +580,7 @@ +(CGColorRef) parseFillForElement:(SVGElement *)svgElement fromFill:(NSString *)actualFill andOpacity:(NSString *)actualFillOpacity { - return [self parsePaintColorForElement:svgElement paintColor:actualFill paintOpacity:actualFillOpacity defaultColor:@"black"]; + return [self parsePaintColorForElement:svgElement paintColor:actualFill paintOpacity:actualFillOpacity defaultColor:@"white"]; } +(CGColorRef) parseStrokeForElement:(SVGElement *)svgElement @@ -592,7 +592,7 @@ +(CGColorRef) parseStrokeForElement:(SVGElement *)svgElement fromStroke:(NSString *)actualStroke andOpacity:(NSString *)actualStrokeOpacity { - return [self parsePaintColorForElement:svgElement paintColor:actualStroke paintOpacity:actualStrokeOpacity defaultColor:@"none"]; + return [self parsePaintColorForElement:svgElement paintColor:actualStroke paintOpacity:actualStrokeOpacity defaultColor:@"white"]; } /** @@ -650,6 +650,15 @@ } } + UIColor *color = [UIColor colorWithCGColor:colorRef]; + if ([color isEqual:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]]) { + return [UIColor whiteColor].CGColor; + } else if ([color isEqual:[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0]]) { + return [UIColor blackColor].CGColor; + } else { + return colorRef; + } + return colorRef; } diff --git a/submodules/Svg/Sources/Svg.m b/submodules/Svg/Sources/Svg.m index f4c9df75e6..7f2308d0df 100755 --- a/submodules/Svg/Sources/Svg.m +++ b/submodules/Svg/Sources/Svg.m @@ -2,27 +2,35 @@ #import "SVGKit.h" #import "SVGKExporterUIImage.h" - + +CGSize aspectFillSize(CGSize size, CGSize bounds) { + CGFloat scale = MAX(bounds.width / MAX(1.0, size.width), bounds.height / MAX(1.0, size.height)); + return CGSizeMake(floor(size.width * scale), floor(size.height * scale)); +} UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size) { NSDate *startTime = [NSDate date]; SVGKImage *image = [[SVGKImage alloc] initWithData:data]; + image.size = aspectFillSize(image.size, size); + if (image == nil) { return nil; } - + double deltaTime = -1.0f * [startTime timeIntervalSinceNow]; //printf("parseTime = %f\n", deltaTime); UIGraphicsBeginImageContextWithOptions(size, true, 1.0); CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); + CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor); CGContextFillRect(context, CGRectMake(0.0f, 0.0f, size.width, size.height)); - startTime = [NSDate date]; + CGContextTranslateCTM(context, (size.width - image.size.width) / 2.0f, (size.height - image.size.height) / 2.0f); + startTime = [NSDate date]; + [image renderToContext:context antiAliased:true curveFlatnessFactor:1.0 interpolationQuality:kCGInterpolationDefault flipYaxis:false]; deltaTime = -1.0f * [startTime timeIntervalSinceNow]; diff --git a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift index 98a7f512c1..bb50580180 100644 --- a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift +++ b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift @@ -73,7 +73,7 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i } } case let .file(file): - if file.isPattern, let color = file.settings.color, let intensity = file.settings.intensity { + if wallpaper.isPattern, let color = file.settings.color, let intensity = file.settings.intensity { var image: UIImage? let _ = 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).start(next: { data in if data.complete { diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index b8a1f3eb5d..dbef4e652a 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -406,7 +406,7 @@ public func serviceColor(for wallpaper: (TelegramWallpaper, UIImage?)) -> UIColo return UIColor(rgb: 0x000000, alpha: 0.3) } case let .file(file): - if file.isPattern { + if wallpaper.0.isPattern { if let color = file.settings.color { var mixedColor = UIColor(argb: color) if let bottomColor = file.settings.bottomColor { @@ -475,7 +475,7 @@ public func chatServiceBackgroundColor(wallpaper: TelegramWallpaper, mediaBox: M return .single(UIColor(rgb: 0x000000, alpha: 0.3)) } case let .file(file): - if file.isPattern { + if wallpaper.isPattern { if let color = file.settings.color { var mixedColor = UIColor(argb: color) if let bottomColor = file.settings.bottomColor { @@ -562,7 +562,7 @@ public func updatedPresentationData(accountManager: AccountManager, applicationI case .builtin, .color, .gradient: effectiveChatWallpaper = themeValue.chat.defaultWallpaper case let .file(file): - if file.isPattern { + if effectiveChatWallpaper.isPattern { effectiveChatWallpaper = themeValue.chat.defaultWallpaper } default: diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift index 0d067a502b..30c8e19f04 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift @@ -138,7 +138,7 @@ extension TelegramWallpaper: Codable { case let .file(file): var components: [String] = [] components.append(file.slug) - if file.isPattern { + if self.isPattern { if let color = file.settings.color { components.append(String(format: "%06x", color)) } diff --git a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift index df80040772..82e7a7903f 100644 --- a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift +++ b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift @@ -9,7 +9,7 @@ public extension TelegramWallpaper { case .image: return false case let .file(file): - if file.isPattern, file.settings.color == 0xffffff { + if self.isPattern, file.settings.color == 0xffffff { return true } else { return false @@ -33,7 +33,7 @@ public extension TelegramWallpaper { var isPattern: Bool { switch self { case let .file(file): - return file.isPattern + return file.isPattern || file.file.mimeType == "image/svg+xml" default: return false } diff --git a/submodules/TelegramUI/BUCK b/submodules/TelegramUI/BUCK index 982d26f152..f705915c30 100644 --- a/submodules/TelegramUI/BUCK +++ b/submodules/TelegramUI/BUCK @@ -202,6 +202,7 @@ framework( "//submodules/ItemListVenueItem:ItemListVenueItem", "//submodules/SemanticStatusNode:SemanticStatusNode", "//submodules/AccountUtils:AccountUtils", + "//submodules/Svg:Svg", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index 024fe914e9..f59cece08d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -2271,7 +2271,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode } } } - } else if let replyInfoNode = self.replyInfoNode, replyInfoNode.frame.contains(location) { + } else if let replyInfoNode = self.replyInfoNode, self.item?.controllerInteraction.tapMessage == nil, replyInfoNode.frame.contains(location) { if let item = self.item { for attribute in item.message.attributes { if let attribute = attribute as? ReplyMessageAttribute { @@ -2305,7 +2305,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode let tapAction = contentNode.tapActionAtPoint(CGPoint(x: location.x - contentNode.frame.minX, y: location.y - contentNode.frame.minY), gesture: gesture) switch tapAction { case .none, .ignore: - if let item = self.item, let tapMessage = self.item?.controllerInteraction.tapMessage { + if let item = self.item, self.backgroundNode.frame.contains(CGPoint(x: self.frame.width - location.x, y: location.y)), let tapMessage = self.item?.controllerInteraction.tapMessage { foundTapAction = true tapMessage(item.message) } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift index 8207cb980e..f482ab3a4d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift @@ -311,6 +311,9 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio dimensions = PixelDimensions(CGSize(width: dimensions.cgSize.height, height: dimensions.cgSize.width)) } unboundSize = CGSize(width: floor(dimensions.cgSize.width * 0.5), height: floor(dimensions.cgSize.height * 0.5)).fitted(CGSize(width: 240.0, height: 240.0)) + } else if file.mimeType == "image/svg+xml" { + let dimensions = CGSize(width: 1440.0, height: 2960.0) + unboundSize = CGSize(width: floor(dimensions.width * 0.5), height: floor(dimensions.height * 0.5)).fitted(CGSize(width: 240.0, height: 240.0)) } else if isTheme { if isSupported { unboundSize = CGSize(width: 160.0, height: 240.0).fitted(CGSize(width: 240.0, height: 240.0)) @@ -586,8 +589,11 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio if isTheme { return themeImage(account: context.account, accountManager: context.sharedContext.accountManager, source: .file(FileMediaReference.message(message: MessageReference(message), media: file))) } else { - 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" { + var representations: [ImageRepresentationWithReference] = file.previewRepresentations.map({ ImageRepresentationWithReference(representation: $0, reference: AnyMediaReference.message(message: MessageReference(message), media: file).resourceReference($0.resource)) }) + if file.mimeType == "image/svg+xml" { + representations.append(ImageRepresentationWithReference(representation: .init(dimensions: PixelDimensions(width: 1440, height: 2960), resource: file.resource), reference: AnyMediaReference.message(message: MessageReference(message), media: file).resourceReference(file.resource))) + } + if ["image/png", "image/svg+xml"].contains(file.mimeType) { return patternWallpaperImage(account: context.account, accountManager: context.sharedContext.accountManager, representations: representations, mode: .thumbnail) } 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) diff --git a/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift b/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift index 3ef0973586..7b5bcfcfd6 100644 --- a/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift +++ b/submodules/TelegramUI/TelegramUI/FetchCachedRepresentations.swift @@ -20,6 +20,7 @@ import LocationResources import ImageBlur import TelegramAnimatedStickerNode import WallpaperResources +import Svg public func fetchCachedResourceRepresentation(account: Account, resource: MediaResource, representation: CachedMediaResourceRepresentation) -> Signal { if let representation = representation as? CachedStickerAJpegRepresentation { @@ -409,11 +410,30 @@ private func fetchCachedBlurredWallpaperRepresentation(resource: MediaResource, private func fetchCachedPatternWallpaperMaskRepresentation(resource: MediaResource, resourceData: MediaResourceData, representation: CachedPatternWallpaperMaskRepresentation) -> Signal { return Signal({ subscriber in if let data = try? Data(contentsOf: URL(fileURLWithPath: resourceData.path), options: [.mappedIfSafe]) { - if let image = UIImage(data: data) { - let path = NSTemporaryDirectory() + "\(arc4random64())" - let url = URL(fileURLWithPath: path) + let path = NSTemporaryDirectory() + "\(arc4random64())" + let url = URL(fileURLWithPath: path) + + if data.count > 5, let string = String(data: data.subdata(in: 0 ..< 5), encoding: .utf8), string == " ParsedInternalUrl? { } else if pathComponents[0] == "bg" { let component = pathComponents[1] let parameter: WallpaperUrlParameter - if component.count == 6, component.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF").inverted) == nil, let color = UIColor(hexString: component) { + if [6, 8].contains(component.count), component.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF").inverted) == nil, let color = UIColor(hexString: component) { parameter = .color(color) - } else if component.count == 13, component.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF-").inverted) == nil { + } else if [13, 15, 17].contains(component.count), component.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF-").inverted) == nil { var rotation: Int32? if let queryItems = components.queryItems { for queryItem in queryItems { @@ -214,9 +214,9 @@ public func parseInternalUrl(query: String) -> ParsedInternalUrl? { } } } else if queryItem.name == "bg_color" { - if value.count == 6, value.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF").inverted) == nil, let color = UIColor(hexString: value) { + if [6, 8].contains(value.count), value.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF").inverted) == nil, let color = UIColor(hexString: value) { topColor = color - } else if value.count == 13, value.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF-").inverted) == nil { + } else if [13, 15, 17].contains(value.count), value.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789abcdefABCDEF-").inverted) == nil { let components = value.components(separatedBy: "-") if components.count == 2, let topColorValue = UIColor(hexString: components[0]), let bottomColorValue = UIColor(hexString: components[1]) { topColor = topColorValue diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index f3ae0e043f..cff2fe4b37 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -194,15 +194,11 @@ public func wallpaperImage(account: Account, accountManager: AccountManager, fil var imageOrientation: UIImage.Orientation = .up if let fullSizeData = fullSizeData { if fullSizeComplete { - if fullSizeData.count > 5, let string = String(data: fullSizeData.subdata(in: 0 ..< 5), encoding: .utf8), string == " mapToSignal { data in if data.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: data.path)), let image = UIImage(data: data) { @@ -1207,7 +1203,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the backgroundColor = (.black, nil) case let .file(file): rotation = file.settings.rotation - if file.isPattern, let color = file.settings.color { + if theme.chat.defaultWallpaper.isPattern, let color = file.settings.color { backgroundColor = (UIColor(rgb: color), file.settings.bottomColor.flatMap { UIColor(rgb: $0) }) } else { backgroundColor = (theme.chatList.backgroundColor, nil) @@ -1225,7 +1221,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the accountManager.mediaBox.storeResourceData(file.file.resource.id, data: fullSizeData) let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() - if file.isPattern { + if wallpaper.wallpaper.isPattern { if let color = file.settings.color, let intensity = file.settings.intensity { return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperRepresentation(color: color, bottomColor: file.settings.bottomColor, intensity: intensity, rotation: file.settings.rotation), complete: true, fetch: true) |> mapToSignal { _ in