From 91965c0c39e2143cc8c3d98c908c2397b1d7d284 Mon Sep 17 00:00:00 2001 From: Sam Steele Date: Tue, 19 Nov 2019 11:02:56 -0500 Subject: [PATCH] Support for loading higher resolution Slack avatars, open Slack avatars in the image viewer --- IRCCloud/Classes/EventsDataSource.m | 7 ++++++- IRCCloud/Classes/URLHandler.m | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/IRCCloud/Classes/EventsDataSource.m b/IRCCloud/Classes/EventsDataSource.m index 0d7119145..11aacc052 100644 --- a/IRCCloud/Classes/EventsDataSource.m +++ b/IRCCloud/Classes/EventsDataSource.m @@ -230,7 +230,12 @@ -(NSURL *)avatar:(int)size { } else if([self->_avatarURL hasPrefix:@"https://"]) { if([self->_avatarURL containsString:@"{size}"]) { CSURITemplate *template = [CSURITemplate URITemplateWithString:self->_avatarURL error:nil]; - self->_cachedAvatarURL = [NSURL URLWithString:[template relativeStringWithVariables:@{@"size":@"72"} error:nil]]; + if(size <= 72) + self->_cachedAvatarURL = [NSURL URLWithString:[template relativeStringWithVariables:@{@"size":@"72"} error:nil]]; + else if(size <= 192) + self->_cachedAvatarURL = [NSURL URLWithString:[template relativeStringWithVariables:@{@"size":@"192"} error:nil]]; + else + self->_cachedAvatarURL = [NSURL URLWithString:[template relativeStringWithVariables:@{@"size":@"512"} error:nil]]; } else { self->_cachedAvatarURL = [NSURL URLWithString:self->_avatarURL]; } diff --git a/IRCCloud/Classes/URLHandler.m b/IRCCloud/Classes/URLHandler.m index 7294e930d..ea097e837 100644 --- a/IRCCloud/Classes/URLHandler.m +++ b/IRCCloud/Classes/URLHandler.m @@ -121,6 +121,8 @@ @implementation URLHandler #define IS_IRCCLOUD_AVATAR(url) ([[url.host lowercaseString] isEqualToString:@"static.irccloud-cdn.com"] && [url.path hasPrefix:@"/avatar-redirect/s"]) +#define IS_SLACK_AVATAR(url) ([[url.host lowercaseString] hasSuffix:@".slack-edge.com"] && ([url.path hasSuffix:@"-72"] || [url.path hasSuffix:@"-192"] || [url.path hasSuffix:@"-512"])) + -(instancetype)init { self = [super init]; @@ -450,7 +452,7 @@ + (BOOL)isImageURL:(NSURL *)url { NSString *l = [url.path lowercaseString]; // Use pre-processor macros instead of variables so conditions are still evaluated lazily - return ([url.scheme.lowercaseString isEqualToString:@"http"] || [url.scheme.lowercaseString isEqualToString:@"https"]) && (HAS_IMAGE_SUFFIX(l) || IS_IMGUR(url) || IS_FLICKR(url) || /*IS_INSTAGRAM(url) ||*/ IS_DROPLR(url) || IS_CLOUDAPP(url) || IS_STEAM(url) || IS_LEET(url) || IS_GIPHY(url) || IS_WIKI(url) || IS_TWIMG(url) || IS_XKCD(url) || IS_IRCCLOUD_AVATAR(url)); + return ([url.scheme.lowercaseString isEqualToString:@"http"] || [url.scheme.lowercaseString isEqualToString:@"https"]) && (HAS_IMAGE_SUFFIX(l) || IS_IMGUR(url) || IS_FLICKR(url) || /*IS_INSTAGRAM(url) ||*/ IS_DROPLR(url) || IS_CLOUDAPP(url) || IS_STEAM(url) || IS_LEET(url) || IS_GIPHY(url) || IS_WIKI(url) || IS_TWIMG(url) || IS_XKCD(url) || IS_IRCCLOUD_AVATAR(url) || IS_SLACK_AVATAR(url)); } + (BOOL)isYouTubeURL:(NSURL *)url