Skip to content

Commit

Permalink
Support for loading higher resolution Slack avatars, open Slack avata…
Browse files Browse the repository at this point in the history
…rs in the image viewer
  • Loading branch information
c99koder committed Nov 19, 2019
1 parent c6600eb commit 91965c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion IRCCloud/Classes/EventsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
4 changes: 3 additions & 1 deletion IRCCloud/Classes/URLHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 91965c0

Please sign in to comment.