1
0
mirror of https://github.com/lint/TFDidThatSay synced 2025-07-01 23:46:47 +00:00

Create helper class to avoid duplicated code

This commit is contained in:
lint
2019-12-29 14:30:17 -05:00
parent 2276c36ce0
commit 70190c98bd
30 changed files with 626 additions and 994 deletions

View File

@ -3,7 +3,7 @@ ARCHS = armv7 armv7s arm64 arm64e
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = tfdidthatsay
tfdidthatsay_FILES = $(wildcard tweak/*.xm tweak/assets/*.m)
tfdidthatsay_FILES = $(wildcard tweak/*.xm tweak/assets/*.m tweak/assets/MMMarkdown/*.m)
tfdidthatsay_CFLAGS = -fobjc-arc
tweak/Reddit.xm_CFLAGS = -fno-objc-arc
tweak/Apollo.xm_CFLAGS = -fno-objc-arc

View File

@ -1,6 +1,7 @@
#import "AlienBlue.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isAlienBlueEnabled;
static BOOL isTFDeletedOnly;
@ -56,43 +57,25 @@ static CGFloat pushshiftRequestTimeoutValue;
id comment = [[self node] comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[%c(TFHelper) getUndeleteDataWithID:[comment ident] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment ident]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
id comment = [[self node] comment];
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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSString *body = data[@"body"];
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[comment setAuthor:author];
[comment setAuthor:data[@"author"]];
[comment setBody:body];
[comment setBodyHTML:bodyHTML];
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO];
[[self delegate] respondToStyleChange];
[sender setEnabled:YES];
}];
[data[@"sender"] setEnabled:YES];
}
%new
@ -100,46 +83,28 @@ static CGFloat pushshiftRequestTimeoutValue;
[sender setEnabled:NO];
id post = [[self node] post];
[%c(TFHelper) getUndeleteDataWithID:[post ident] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = [[self node] post];
id postComment = [[self node] comment]; //Don't know why he used a comment to store info about a post, but it exists
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 ident]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSString *body = data[@"body"];
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[post setAuthor:author];
[post setAuthor:data[@"author"]];
[post setSelftext:body];
[postComment setBodyHTML:bodyHTML];
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO];
[[self delegate] respondToStyleChange];
[sender setEnabled:YES];
}];
[data[@"sender"] setEnabled:YES];
}
%end
@ -196,4 +161,3 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
}
}
}

View File

@ -1,6 +1,7 @@
#import "Antenna.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isAntennaEnabled;
static BOOL isTFDeletedOnly;
@ -48,37 +49,18 @@ id tfAntennaCommentCell;
%new
-(void) handleUndeleteCommentAction{
[%c(TFHelper) getUndeleteDataWithID:[[tfAntennaCommentCell comment] itemId] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = [tfAntennaCommentCell comment];
id commentText = [comment commentText];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSString *body = data[@"body"];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment itemId]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[comment setAuthor:author];
[comment setAuthor:data[@"author"]];
[commentText setBody:body];
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
@ -87,9 +69,8 @@ id tfAntennaCommentCell;
[commentText setTextHeightCache:nil];
[self setCommentHeightCache:nil];
[tfAntennaCommentCell performSelectorOnMainThread:@selector(updateWithModelObject:) withObject:comment waitUntilDone:YES];
[[[self delegate] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}];
[tfAntennaCommentCell updateWithModelObject:comment];
[[[self delegate] tableView] reloadData];
}
%end
@ -178,37 +159,18 @@ id tfAntennaCommentCell;
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[[self post] itemId] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = [self post];
id postText = [post selfCommentText];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSString *body = data[@"body"];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[post itemId]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[post setAuthor:author];
[post setAuthor:data[@"author"]];
[postText setBody:body];
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
@ -216,11 +178,10 @@ id tfAntennaCommentCell;
[postText setBodyAttributedStringForPreview:nil];
[postText setTextHeightCache:nil];
[self performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[self loadView];
[[self tableView] reloadData];
[sender setEnabled:YES];
}];
[data[@"sender"] setEnabled:YES];
}
%end

View File

@ -1,5 +1,6 @@
#import "Apollo.h"
#import "assets/TFHelper.h"
static BOOL isTFDeletedOnly;
static BOOL isApolloEnabled;
@ -38,59 +39,6 @@ NSDictionary* apolloBodyAttributes = nil;
%hook ApolloCommentCellNode
%property(strong,nonatomic) id undeleteButton;
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id authorNode = MSHookIvar<id>(self, "authorNode");
id authorTextNode = [authorNode subnodes][0];
id comment = MSHookIvar<id>(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 fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[comment setAuthor:author];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
[sender setEnabled:YES];
}];
}
-(void) didLoad {
%orig;
@ -128,71 +76,49 @@ NSDictionary* apolloBodyAttributes = nil;
CGFloat nodeSpacing =[ageNode frame].origin.x - nodeFrame.origin.x - nodeFrame.size.width;
[[self undeleteButton] setFrame:CGRectMake(nodeFrame.origin.x - imageSize - nodeSpacing, centerHeight - (imageSize / 2), imageSize, imageSize)];
}
}
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id comment = MSHookIvar<id>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = MSHookIvar<id>(self, "comment");
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id authorNode = MSHookIvar<id>(self, "authorNode");
id authorTextNode = [authorNode subnodes][0];
NSString *author = data[@"author"];
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString *newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[comment setAuthor:author];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:data[@"body"] withAttributes:apolloBodyAttributes]];
[data[@"sender"] setEnabled:YES];
}
%end
%hook ApolloCommentsHeaderCellNode
%property(strong, nonatomic) id undeleteButton;
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id postInfoNode = MSHookIvar<id>(self, "postInfoNode");
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode");
id authorTextNode = [authorNode subnodes][0];
id post = MSHookIvar<id>(self, "link");
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 fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
//MSHookIvar<NSString*>(post, "_author") = author; //Crashes when clicking on author name. You will have to search the author name to go find the profile.
author = [NSString stringWithFormat:@"by %@", author];
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
[sender setEnabled:YES];
}];
}
-(void) didLoad{
%orig;
@ -234,6 +160,43 @@ NSDictionary* apolloBodyAttributes = nil;
}
}
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id post = MSHookIvar<id>(self, "link");
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id postInfoNode = MSHookIvar<id>(self, "postInfoNode");
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode");
id authorTextNode = [authorNode subnodes][0];
NSString *author = data[@"author"];
//id post = MSHookIvar<id>(self, "link");
//MSHookIvar<NSString*>(post, "_author") = author; //Crashes when clicking on author name. You will have to search the author name to go find the profile.
author = [NSString stringWithFormat:@"by %@", author];
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:data[@"body"] withAttributes:apolloBodyAttributes]];
[data[@"sender"] setEnabled:YES];
}
%end
%end

View File

@ -1,6 +1,7 @@
#import "BaconReader.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isBaconReaderEnabled;
static BOOL isTFDeletedOnly;
@ -126,36 +127,17 @@ id tfStoryController;
%new
-(void) handleUndeleteCommentAction{
[%c(TFHelper) getUndeleteDataWithID:[[tfCommentCellView comment] serverID] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = [tfCommentCellView comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSString *body = data[@"body"];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", [comment serverID]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[comment setAuthor:author];
[comment setAuthor:data[@"author"]];
[comment setBody:body];
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[comment setAttributedDescriptionString:nil];
@ -163,48 +145,22 @@ id tfStoryController;
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment];
[comment setAttributedDescriptionString:commentAttrString];
[[[self detailPage] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}];
[[[self detailPage] tableView] reloadData];
}
%new
-(void) handleUndeletePostAction{
id post = [self story];
[%c(TFHelper) getUndeleteDataWithID:[[self story] serverID] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", [post serverID]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
tfPostAuthor = data[@"author"];
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
tfPostAuthor = author;
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[[self detailPage] performSelectorOnMainThread:@selector(refreshTouched) withObject:nil waitUntilDone:NO];
}];
[[self detailPage] refreshTouched];
}
%end

View File

@ -1,5 +1,6 @@
#import "Beam.h"
#import "assets/TFHelper.h"
static BOOL isBeamEnabled;
static BOOL isTFDeletedOnly;
@ -25,8 +26,6 @@ static CGFloat pushshiftRequestTimeoutValue;
NSString *commentBody = [[self comment] content];
HBLogDebug(@"body: %@", commentBody);
if ((isTFDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isTFDeletedOnly){
CGFloat authorTextHeight = [[self authorButton] frame].size.height;
@ -51,45 +50,23 @@ static CGFloat pushshiftRequestTimeoutValue;
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[[self comment] identifier] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id 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 identifier]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[comment setAuthor:author];
[comment setContent:body];
[comment setAuthor:data[@"author"]];
[comment setContent:data[@"body"]];
[comment setMarkdownString:nil];
[self setCommentDidChange:YES];
[self performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES];
[[MSHookIvar<id>(self, "delegate") tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[self reloadContents];
[[MSHookIvar<id>(self, "delegate") tableView] reloadData];
[sender setEnabled:YES];
}];
[data[@"sender"] setEnabled:YES];
}
%end
@ -174,50 +151,30 @@ static CGFloat pushshiftRequestTimeoutValue;
if (post){
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 identifier]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
[%c(TFHelper) getUndeleteDataWithID:[post identifier] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
[post setAuthor:author];
[post setContent:body];
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = [self post];
[post setAuthor:data[@"author"]];
[post setContent:data[@"body"]];
[post setMarkdownString:nil];
if ([self selfTextView]){
[[self selfTextView] performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES];
[[self selfTextView] reloadContents];
}
if ([self metadataView]){
[[self metadataView] performSelectorOnMainThread:@selector(setPost:) withObject:post waitUntilDone:YES];
[[self metadataView] setPost:post];
}
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:post waitUntilDone:NO];
[[self tableView] reloadData];
[sender setEnabled:YES];
}];
}
[data[@"sender"] setEnabled:YES];
}
%end
@ -274,4 +231,3 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
}
}
}

View File

@ -1,5 +1,6 @@
#import "Narwhal.h"
#import "assets/TFHelper.h"
static BOOL isNarwhalEnabled;
static BOOL isTFDeletedOnly;
@ -12,37 +13,7 @@ id tfComment;
id tfController;
void getUndeleteCommentData(id controller, id 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 fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[controller performSelectorOnMainThread:@selector(completeUndeleteComment:) withObject:@{@"body":body, @"author":author, @"comment":comment} waitUntilDone:NO];
}];
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"comment" : comment} completionTarget:controller completionSelector:@selector(completeUndeleteCommentAction:)];
}
@ -61,7 +32,6 @@ void getUndeleteCommentData(id controller, id comment){
}
[arg1 addAction:undeleteAction];
}
%orig;
@ -72,70 +42,6 @@ void getUndeleteCommentData(id controller, id comment){
%hook NRTLinkViewController
%new
-(void) completeUndeleteComment:(id) data{
id comment = data[@"comment"];
if (comment){
MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}
%new
-(void) completeUndeletePost:(id) data{
id post = data[@"post"];
MSHookIvar<NSString*>(post, "_author") = data[@"author"];
NSAttributedString* postBodyAttributedString = [%c(NRTMarkdownManager) attributedStringFromMarkdown:data[@"body"] type:0];
[self setLinkText:postBodyAttributedString];
[[self tableView] reloadData];
}
%new
-(void) handleUndeletePostAction{
id post = [self link];
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 fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[self performSelectorOnMainThread:@selector(completeUndeletePost:) withObject:@{@"body":body, @"author":author, @"post":post} waitUntilDone:NO];
}];
}
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
if (arg2 == 2){
@ -174,13 +80,29 @@ void getUndeleteCommentData(id controller, id comment){
shouldHaveUndeleteAction = NO;
}
%end
%new
-(void) handleUndeletePostAction{
id post = [self link];
%hook NRTMediaTableViewDataSource
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"post" : post} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeleteComment:(id) data{
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = data[@"post"];
MSHookIvar<NSString*>(post, "_author") = data[@"author"];
NSAttributedString* postBodyAttributedString = [%c(NRTMarkdownManager) attributedStringFromMarkdown:data[@"body"] type:0];
[self setLinkText:postBodyAttributedString];
[[self tableView] reloadData];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = data[@"comment"];
@ -193,6 +115,11 @@ void getUndeleteCommentData(id controller, id comment){
}
}
%end
%hook NRTMediaTableViewDataSource
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
if (arg2 == 2){
@ -213,6 +140,20 @@ void getUndeleteCommentData(id controller, id comment){
shouldHaveUndeleteAction = NO;
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = data[@"comment"];
if (comment){
MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}
%end
%end

View File

@ -21,6 +21,10 @@
-(void) reloadPostSection:(BOOL) arg1;
-(void) feedPostViewDidUpdatePost:(id) arg1 shouldReloadFeed:(BOOL) arg2;
-(void) updateFloatingViews;
//custom elements
-(void) updateComments;
-(void) updatePostText;
@end
@interface CommentActionSheetViewController : UIViewController

View File

@ -1,5 +1,6 @@
#import "Reddit.h"
#import "assets/TFHelper.h"
static BOOL isRedditEnabled;
static BOOL isTFDeletedOnly;
@ -94,32 +95,18 @@ int getRedditVersionPart(int index){
id commentTreeNode = [self commentTreeNode];
Comment *comment = [commentTreeNode 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"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id commentTreeNode = [self commentTreeNode];
Comment *comment = [commentTreeNode comment];
NSString *author = data[@"author"];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText;
@ -176,15 +163,11 @@ int getRedditVersionPart(int index){
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
[comment setBodyAttributedText:bodyMutableAttributedText];
[[commentTreeNode commentTreeHeaderNode] performSelectorOnMainThread:@selector(updateContentViewsForData:) withObject:comment waitUntilDone:NO];
[[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
}
}
%end
@ -242,32 +225,17 @@ int getRedditVersionPart(int index){
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"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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]";
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
Post *post = [self post];
NSString *author = data[@"author"];
NSString *body = data[@"body"];
id themeManager;
id isNightMode;
@ -331,13 +299,9 @@ int getRedditVersionPart(int index){
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
}
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
}
}
}
%end
%end
@ -405,46 +369,7 @@ int getRedditVersionPart(int index){
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"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
[comment setBodyAttributedText:bodyMutableAttributedText];
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
@ -458,36 +383,20 @@ int getRedditVersionPart(int index){
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"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
Comment *comment = [self comment];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:author];
[comment setAuthor:data[@"author"]];
[comment setBodyText:body];
[comment setBodyAttributedText:bodyMutableAttributedText];
@ -495,13 +404,9 @@ int getRedditVersionPart(int index){
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
}
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
[[self commentActionSheetDelegate] updateComments];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
}
}
%end
@ -552,46 +457,7 @@ int getRedditVersionPart(int index){
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"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setSelfText:body];
[post setAuthor:author];
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
[[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
@ -608,36 +474,21 @@ int getRedditVersionPart(int index){
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"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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]";
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
Post *post = [self post];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setAuthor:author];
[post setAuthor:data[@"author"]];
[post setSelfText:body];
[post setSelfTextAttributed:bodyMutableAttributedText];
@ -649,15 +500,11 @@ int getRedditVersionPart(int index){
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
}
[[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
[[self postActionSheetDelegate] updatePostText];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
}
}
}
%end
%end

View File

@ -1,6 +1,7 @@
#import "Slide.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isSlideEnabled;
static BOOL isTFDeletedOnly;
@ -289,36 +290,20 @@ static UIButton * createUndeleteButton(){
[sender setEnabled:NO];
id comment = MSHookIvar<id>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment id] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
id textStackDisplayView = MSHookIvar<id>(self, "commentBody");
id comment = MSHookIvar<id>(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 id] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSString *author = data[@"author"];
NSString *body = data[@"body"];
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
@ -406,11 +391,10 @@ static UIButton * createUndeleteButton(){
id controller = MSHookIvar<id>(self, "parent");
[self performSelectorOnMainThread:@selector(showMenu:) withObject:nil waitUntilDone:YES];
[MSHookIvar<id>(controller, "tableView") performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[self showMenu:nil];
[MSHookIvar<id>(controller, "tableView") reloadData];
[sender setEnabled:YES];
}];
[data[@"sender"] setEnabled:YES];
}
%end

6
tweak/assets/TFHelper.h Normal file
View File

@ -0,0 +1,6 @@
@interface TFHelper : NSObject
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel;
@end

50
tweak/assets/TFHelper.m Normal file
View File

@ -0,0 +1,50 @@
#import "TFHelper.h"
@implementation TFHelper
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
if (isComment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
} else {
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", ident]]];
}
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:timeout];
[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] objectForKey:@"data"];
if ([jsonData count] != 0){
author = [jsonData[0] objectForKey:@"author"];
body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[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 = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableDictionary *result = [@{@"author" : author, @"body" : body} mutableCopy];
if (extra){
[result addEntriesFromDictionary:extra];
}
[target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
}];
}
@end