Browse Source

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

master
lint 5 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

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

+ 8
- 0
tweak/Reddit.h View File

@end @end
@interface CommentsViewController : NSObject @interface CommentsViewController : NSObject
@property(strong,nonatomic) id postData;
-(void) reloadCommentsWithNewCommentsHighlight:(BOOL) arg1 autoScroll:(BOOL) arg2 animated:(BOOL) arg3; -(void) reloadCommentsWithNewCommentsHighlight:(BOOL) arg1 autoScroll:(BOOL) arg2 animated:(BOOL) arg3;
-(void) reloadCommentsSection:(BOOL) arg1; -(void) reloadCommentsSection:(BOOL) arg1;
-(void) reloadPostSection:(BOOL) arg1; -(void) reloadPostSection:(BOOL) arg1;
-(id) initWithLeftIconImage:(id) arg1 text:(id) arg2 identifier:(id) arg3 context:(id) arg4; -(id) initWithLeftIconImage:(id) arg1 text:(id) arg2 identifier:(id) arg3 context:(id) arg4;
@end @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 @interface RUITheme
@property(strong,nonatomic) id bodyTextColor; @property(strong,nonatomic) id bodyTextColor;
@end @end

+ 152
- 13
tweak/Reddit.xm View File

%end %end
%group Reddit_v4_ios10 %group Reddit_v4_ios10
%hook CommentsViewController %hook CommentsViewController
%new %new
-(void) updatePostText{ -(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 %end
CGFloat scale = origImage.size.width / existingImageSize.width; CGFloat scale = origImage.size.width / existingImageSize.width;
UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation]; 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]); %orig([arg1 arrayByAddingObject:undeleteItem]);
[undeleteItem release]; [undeleteItem release];
} }
// >= 4.21
-(void) handleDidSelectActionSheetItem:(id) arg1{ -(void) handleDidSelectActionSheetItem:(id) arg1{
%orig; %orig;
}]; }];
} }
} }
// <= 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 %end
CGFloat scale = origImage.size.width / existingImageSize.width; CGFloat scale = origImage.size.width / existingImageSize.width;
UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation]; 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]; arg1 = [arg1 arrayByAddingObject:undeleteItem];
%orig; %orig;
} }
// >= 4.21
-(void) handleDidSelectActionSheetItem:(id) arg1{ -(void) handleDidSelectActionSheetItem:(id) arg1{
%orig; %orig;
} }
} }
} }
%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
%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 %group Reddit_v3
%hook CommentView %hook CommentView
} }
} }
} }

Loading…
Cancel
Save