Browse Source

Add more Reddit support (4.0 ->) for some reason

master
lint 4 years ago
parent
commit
f8dafd9467
3 changed files with 161 additions and 14 deletions
  1. +1
    -1
      control
  2. +8
    -0
      tweak/Reddit.h
  3. +152
    -13
      tweak/Reddit.xm

+ 1
- 1
control View File

@@ -1,7 +1,7 @@
Package: com.lint.undelete
Name: TFDidThatSay?
Depends: mobilesubstrate
Version: 1.2.5
Version: 1.2.6
Architecture: iphoneos-arm
Description: See "[deleted]" comments and posts without leaving Reddit!
Maintainer: lint <apieceoflint@protonmail.com>

+ 8
- 0
tweak/Reddit.h View File

@@ -15,6 +15,7 @@
@end
@interface CommentsViewController : NSObject
@property(strong,nonatomic) id postData;
-(void) reloadCommentsWithNewCommentsHighlight:(BOOL) arg1 autoScroll:(BOOL) arg2 animated:(BOOL) arg3;
-(void) reloadCommentsSection:(BOOL) arg1;
-(void) reloadPostSection:(BOOL) arg1;
@@ -128,6 +129,13 @@
-(id) initWithLeftIconImage:(id) arg1 text:(id) arg2 identifier:(id) arg3 context:(id) arg4;
@end
@interface ActionSheetItem : NSObject
// <= 4.17
@property(strong,nonatomic) id leftIconImage;
-(id) initWithLeftIconImage:(id) arg1 text:(id) arg2 identifier:(id) arg3 context:(id) arg4;
@end
@interface RUITheme
@property(strong,nonatomic) id bodyTextColor;
@end

+ 152
- 13
tweak/Reddit.xm View File

@@ -316,7 +316,6 @@
%end
%group Reddit_v4_ios10
%hook CommentsViewController
@@ -328,7 +327,13 @@
%new
-(void) updatePostText{
[self reloadPostSection:YES];
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([appVersion[1] integerValue] >= 2){
[self reloadPostSection:YES];
} else {
[self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
}
}
%end
@@ -343,14 +348,23 @@
CGFloat scale = origImage.size.width / existingImageSize.width;
UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
id undeleteItem;
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([appVersion[1] integerValue] >= 18) {
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
} else {
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
}
%orig([arg1 arrayByAddingObject:undeleteItem]);
[undeleteItem release];
}
// >= 4.21
-(void) handleDidSelectActionSheetItem:(id) arg1{
%orig;
@@ -401,6 +415,63 @@
}];
}
}
// <= 4.20
-(void) actionSheetViewController:(id) arg1 didSelectItem:(id) arg2{
%orig;
if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
[self dismissViewControllerAnimated:YES completion:nil];
Comment *comment = [self comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = @"[an error occured]";
}
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyAttributedText:bodyMutableAttributedText];
if ([appVersion[1] integerValue] >= 12) {
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
}
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
}
}
%end
@@ -418,8 +489,16 @@
CGFloat scale = origImage.size.width / existingImageSize.width;
UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
id undeleteItem;
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([appVersion[1] integerValue] >= 18) {
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
} else {
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
}
arg1 = [arg1 arrayByAddingObject:undeleteItem];
@@ -429,7 +508,7 @@
%orig;
}
// >= 4.21
-(void) handleDidSelectActionSheetItem:(id) arg1{
%orig;
@@ -483,12 +562,77 @@
}
}
}
%end
// <= 4.20
-(void) actionSheetViewController:(id) arg1 didSelectItem:(id) arg2{
%orig;
if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
[self dismissViewControllerAnimated:YES completion:nil];
Post *post = [self post];
if ([post isSelfPost]){
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = @"[an error occured]";
}
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setAuthor:author];
[post setSelfText:body];
[post setSelfTextAttributed:bodyMutableAttributedText];
if ([appVersion[1] integerValue] >= 8) {
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
}
if ([appVersion[1] integerValue] >= 15) {
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
}
[[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
}
}
}
%end
%end
//outdated and unchanged from first version of this tweak...
//TODO: move button to menu, add post support, make async requests once I feel like doing it
%group Reddit_v3
%hook CommentView
@@ -589,8 +733,3 @@
}
}
}

Loading…
Cancel
Save