From 8028166b15dc3c46d6d3418ef0943d3711f42f11 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 24 Aug 2018 07:28:53 +0300 Subject: [PATCH] no message --- LegacyComponents/TGMediaOriginInfo.m | 14 ++++++++++---- LegacyComponents/TGRemoteImageView.m | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/LegacyComponents/TGMediaOriginInfo.m b/LegacyComponents/TGMediaOriginInfo.m index 1c0ac8cb76..a41c9a805f 100644 --- a/LegacyComponents/TGMediaOriginInfo.m +++ b/LegacyComponents/TGMediaOriginInfo.m @@ -101,7 +101,10 @@ break; case TGMediaOriginTypeWebpage: - info->_webpageUrl = keyComponents[1]; + { + NSString *url = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (CFStringRef)keyComponents[1], CFSTR(""), kCFStringEncodingUTF8); + info->_webpageUrl = url; + } break; case TGMediaOriginTypeWallpaper: @@ -111,11 +114,11 @@ default: return nil; } - if ([components[1] length] > 0) + if (components.count > 1 && [components[1] length] > 0) info->_fileReference = [NSData dataWithHexString:components[1]]; NSMutableDictionary *fileReferences = [[NSMutableDictionary alloc] init]; - if ([components[2] length] > 0) + if (components.count > 2 && [components[2] length] > 0) { NSArray *refComponents = [components[2] componentsSeparatedByString:@","]; for (NSString *ref in refComponents) @@ -174,7 +177,10 @@ return [NSString stringWithFormat:@"%d|%@", _type, _chatPhotoPeerId]; case TGMediaOriginTypeWebpage: - return [NSString stringWithFormat:@"%d|%@", _type, _webpageUrl]; + { + NSString *url = [TGStringUtils stringByEscapingForURL:_webpageUrl]; + return [NSString stringWithFormat:@"%d|%@", _type, url]; + } case TGMediaOriginTypeWallpaper: return [NSString stringWithFormat:@"%d|%@", _type, _wallpaperId]; diff --git a/LegacyComponents/TGRemoteImageView.m b/LegacyComponents/TGRemoteImageView.m index f1929fb3f9..d11cf92759 100644 --- a/LegacyComponents/TGRemoteImageView.m +++ b/LegacyComponents/TGRemoteImageView.m @@ -13,6 +13,7 @@ static TGCache *sharedCache = nil; @interface TGRemoteImageView () @property (atomic, strong) NSString *path; +@property (atomic, strong) NSString *currentCacheUrl; @property (nonatomic, strong) UIImageView *placeholderView; @@ -231,8 +232,13 @@ static TGCache *sharedCache = nil; TGCache *cache = _cache != nil ? _cache : [TGRemoteImageView sharedCache]; - NSString *cacheUrl = filter == nil ? url : [[NSString alloc] initWithFormat:@"{filter:%@}%@", filter, url]; + NSString *trimmedUrl = url; + NSArray *components = [trimmedUrl componentsSeparatedByString:@"_"]; + if (components.count >= 5) + trimmedUrl = [NSString stringWithFormat:@"%@_%@_%@_%@", components[0], components[1], components[2], components[3]]; + NSString *cacheUrl = filter == nil ? trimmedUrl : [[NSString alloc] initWithFormat:@"{filter:%@}%@", filter, trimmedUrl]; + self.currentCacheUrl = cacheUrl; UIImage *image = [cache cachedImage:cacheUrl availability:TGCacheMemory]; if (image == nil) @@ -461,7 +467,7 @@ static TGCache *sharedCache = nil; if (_useCache) { TGCache *cache = _cache != nil ? _cache : [TGRemoteImageView sharedCache]; - [cache cacheImage:image withData:nil url:self.currentUrl availability:TGCacheMemory]; + [cache cacheImage:image withData:nil url:self.currentCacheUrl availability:TGCacheMemory]; } #endif