Skip to content

Commit

Permalink
Fix crash when tapping on spoiler tag
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyCA committed Dec 3, 2023
1 parent e076a05 commit 88cb2b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 5 additions & 1 deletion 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.5] - 2023-12-02

- Fix crash when tapping on spoiler tag

## [v1.0.4] - 2023-11-29

Add support for share links (e.g. `reddit.com/r/subreddit/s/xxxxxx`) in Apollo. These links are obfuscated and require loading them in the background to resolve them to the standard Reddit link format that can be understood by 3rd party apps.
Expand All @@ -25,9 +29,9 @@ There are currently a few limitations:
## [v1.0.0] - 2023-10-13
- Initial release

[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
[v1.0.2c]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.1...v1.0.2c
[v1.0.1]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.0...v1.0.1
[v1.0.0]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.0.0

24 changes: 18 additions & 6 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -179,29 +179,37 @@ static void TryResolveShareUrl(NSString *urlString, void (^successHandler)(NSStr
// Tappable text link in an inbox item (*not* the links in the PM chat bubbles)
%hook _TtC6Apollo13InboxCellNode

-(void)textNode:(id)textNode tappedLinkAttribute:(id)attr value:(NSURL *)url atPoint:(struct CGPoint)point textRange:(struct _NSRange)range {
-(void)textNode:(id)textNode tappedLinkAttribute:(id)attr value:(id)val atPoint:(struct CGPoint)point textRange:(struct _NSRange)range {
if (![val isKindOfClass:[NSURL class]]) {
%orig;
return;
}
void (^ignoreHandler)(void) = ^{
%orig;
};
void (^successHandler)(NSString *) = ^(NSString *resolvedURL) {
%orig(textNode, attr, [NSURL URLWithString:resolvedURL], point, range);
};
TryResolveShareUrl([url absoluteString], successHandler, ignoreHandler);
TryResolveShareUrl([val absoluteString], successHandler, ignoreHandler);
}

%end

// Text view containing markdown and tappable links, can be in the header of a post or a comment
%hook _TtC6Apollo12MarkdownNode

-(void)textNode:(id)textNode tappedLinkAttribute:(id)attr value:(NSURL *)url atPoint:(struct CGPoint)point textRange:(struct _NSRange)range {
-(void)textNode:(id)textNode tappedLinkAttribute:(id)attr value:(id)val atPoint:(struct CGPoint)point textRange:(struct _NSRange)range {
if (![val isKindOfClass:[NSURL class]]) {
%orig;
return;
}
void (^ignoreHandler)(void) = ^{
%orig;
};
void (^successHandler)(NSString *) = ^(NSString *resolvedURL) {
%orig(textNode, attr, [NSURL URLWithString:resolvedURL], point, range);
};
TryResolveShareUrl([url absoluteString], successHandler, ignoreHandler);
TryResolveShareUrl([val absoluteString], successHandler, ignoreHandler);
}

%end
Expand Down Expand Up @@ -234,14 +242,18 @@ static void TryResolveShareUrl(NSString *urlString, void (^successHandler)(NSStr
TryResolveShareUrl(urlString, successHandler, ignoreHandler);
}

-(void)textNode:(id)textNode tappedLinkAttribute:(id)attr value:(NSURL *)url atPoint:(struct CGPoint)point textRange:(struct _NSRange)range {
-(void)textNode:(id)textNode tappedLinkAttribute:(id)attr value:(id)val atPoint:(struct CGPoint)point textRange:(struct _NSRange)range {
if (![val isKindOfClass:[NSURL class]]) {
%orig;
return;
}
void (^ignoreHandler)(void) = ^{
%orig;
};
void (^successHandler)(NSString *) = ^(NSString *resolvedURL) {
%orig(textNode, attr, [NSURL URLWithString:resolvedURL], point, range);
};
TryResolveShareUrl([url absoluteString], successHandler, ignoreHandler);
TryResolveShareUrl([val absoluteString], successHandler, ignoreHandler);
}

%end
Expand Down

0 comments on commit 88cb2b9

Please sign in to comment.