Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyCA committed Dec 8, 2023
2 parents d4af529 + 4a2e43e commit a4d6439
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [v1.0.7] - 2023-12-07

- Add support for resolving Reddit media share links ([#9](https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/pull/9)) - thanks [@mmshivesh](https://github.com/mmshivesh)!

## [v1.0.5] - 2023-12-02

- Fix crash when tapping on spoiler tag
Expand Down Expand Up @@ -29,6 +33,7 @@ There are currently a few limitations:
## [v1.0.0] - 2023-10-13
- Initial release

[v1.0.7]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.5...v1.0.7
[v1.0.5]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.4...v1.0.5
[v1.0.4]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.3b...v1.0.4
[v1.0.3b]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.2c...v1.0.3b
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Apollo for Reddit with in-app configurable API keys and several fixes and improv
- Handle x.com links as Twitter links so that they can be opened in the Twitter app
- Suppress unwanted messages on app startup (wallpaper popup, in-app announcements, etc)
- Support new share link format (reddit.com/r/subreddit/s/xxxxxx) so they open like any other post and not in a browser
- Support media share links (reddit.com/media?url=)

## Known issues
- Apollo Ultra features may cause app to crash
Expand Down
14 changes: 14 additions & 0 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ static NSArray *blockedUrls = @[
static NSString *const ShareLinkRegexPattern = @"^(?:https?:)?//(?:www\\.)?reddit\\.com/r/(\\w+)/s/(\\w+)$";
static NSRegularExpression *ShareLinkRegex;

// Regex for media share links
static NSString *const MediaShareLinkPattern = @"^(?:https?:)?//(?:www\\.)?reddit\\.com/media\\?url=(.*?)$";
static NSRegularExpression *MediaShareLinkRegex;

// Cache storing resolved share URLs - this is an optimization so that we don't need to resolve the share URL every time
static NSCache <NSString *, ShareUrlTask *> *cache;

Expand Down Expand Up @@ -164,6 +168,15 @@ static void TryResolveShareUrl(NSString *urlString, void (^successHandler)(NSStr
// This exits early if already in cache
StartShareURLResolveTask(string);
}
// Fix Reddit Media URL redirects, for example this comment: https://reddit.com/r/TikTokCringe/comments/18cyek4/_/kce86er/?context=1 has an image link in this format: https://www.reddit.com/media?url=https%3A%2F%2Fi.redd.it%2Fpdnxq8dj0w881.jpg
NSTextCheckingResult *mediaMatch = [MediaShareLinkRegex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])];
if (mediaMatch) {
NSRange media = [mediaMatch rangeAtIndex:1];
NSString *encodedURLString = [string substringWithRange:media];
NSString *decodedURLString = [encodedURLString stringByRemovingPercentEncoding];
NSURL *decodedURL = [NSURL URLWithString:decodedURLString];
return decodedURL;
}
return %orig;
}

Expand Down Expand Up @@ -522,6 +535,7 @@ static NSString *imageID;
cache = [NSCache new];
NSError *error = NULL;
ShareLinkRegex = [NSRegularExpression regularExpressionWithPattern:ShareLinkRegexPattern options:NSRegularExpressionCaseInsensitive error:&error];
MediaShareLinkRegex = [NSRegularExpression regularExpressionWithPattern:MediaShareLinkPattern options:NSRegularExpressionCaseInsensitive error:&error];

NSDictionary *defaultValues = @{UDKeyBlockAnnouncements: @YES};
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ca.jeffrey.apollo-improvedcustomapi
Name: Apollo-ImprovedCustomApi
Version: 1.0.6b~experimental
Version: 1.0.7~experimental
Architecture: iphoneos-arm
Description: Apollo for Reddit tweak with in-app configurable API keys
Maintainer: JeffreyCA
Expand Down

0 comments on commit a4d6439

Please sign in to comment.