mirror of
https://github.com/lint/TFDidThatSay
synced 2025-07-04 08:36:45 +00:00
Add more Reddit support (4.0 ->) for some reason
This commit is contained in:
2
control
2
control
@ -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>
|
||||
|
@ -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
|
||||
|
159
tweak/Reddit.xm
159
tweak/Reddit.xm
@ -316,7 +316,6 @@
|
||||
%end
|
||||
|
||||
|
||||
|
||||
%group Reddit_v4_ios10
|
||||
|
||||
%hook CommentsViewController
|
||||
@ -328,7 +327,13 @@
|
||||
|
||||
%new
|
||||
-(void) updatePostText{
|
||||
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
|
||||
|
||||
if ([appVersion[1] integerValue] >= 2){
|
||||
[self reloadPostSection:YES];
|
||||
} else {
|
||||
[self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
|
||||
}
|
||||
}
|
||||
|
||||
%end
|
||||
@ -344,13 +349,22 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -419,7 +490,15 @@
|
||||
|
||||
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 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// <= 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 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user