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:
2
Makefile
2
Makefile
@ -3,7 +3,7 @@ ARCHS = armv7 armv7s arm64 arm64e
|
|||||||
include $(THEOS)/makefiles/common.mk
|
include $(THEOS)/makefiles/common.mk
|
||||||
|
|
||||||
TWEAK_NAME = tfdidthatsay
|
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
|
tfdidthatsay_CFLAGS = -fobjc-arc
|
||||||
tweak/Reddit.xm_CFLAGS = -fno-objc-arc
|
tweak/Reddit.xm_CFLAGS = -fno-objc-arc
|
||||||
tweak/Apollo.xm_CFLAGS = -fno-objc-arc
|
tweak/Apollo.xm_CFLAGS = -fno-objc-arc
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#import "AlienBlue.h"
|
#import "AlienBlue.h"
|
||||||
#import "assets/MMMarkdown.h"
|
#import "assets/TFHelper.h"
|
||||||
|
#import "assets/MMMarkdown/MMMarkdown.h"
|
||||||
|
|
||||||
static BOOL isAlienBlueEnabled;
|
static BOOL isAlienBlueEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -56,43 +57,25 @@ static CGFloat pushshiftRequestTimeoutValue;
|
|||||||
|
|
||||||
id comment = [[self node] comment];
|
id comment = [[self node] comment];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[comment ident] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
|
||||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
}
|
||||||
|
|
||||||
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment ident]]]];
|
%new
|
||||||
[request setHTTPMethod:@"GET"];
|
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
|
||||||
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
|
|
||||||
|
|
||||||
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
|
id comment = [[self node] comment];
|
||||||
|
|
||||||
NSString *author = @"[author]";
|
NSString *body = data[@"body"];
|
||||||
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 *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
|
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
|
||||||
|
|
||||||
[comment setAuthor:author];
|
[comment setAuthor:data[@"author"]];
|
||||||
[comment setBody:body];
|
[comment setBody:body];
|
||||||
[comment setBodyHTML:bodyHTML];
|
[comment setBodyHTML:bodyHTML];
|
||||||
|
|
||||||
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO];
|
[[self delegate] respondToStyleChange];
|
||||||
|
|
||||||
[sender setEnabled:YES];
|
[data[@"sender"] setEnabled:YES];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%new
|
%new
|
||||||
@ -100,46 +83,28 @@ static CGFloat pushshiftRequestTimeoutValue;
|
|||||||
|
|
||||||
[sender setEnabled:NO];
|
[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 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
|
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];
|
NSString *body = data[@"body"];
|
||||||
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 *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
|
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
|
||||||
|
|
||||||
[post setAuthor:author];
|
[post setAuthor:data[@"author"]];
|
||||||
[post setSelftext:body];
|
[post setSelftext:body];
|
||||||
[postComment setBodyHTML:bodyHTML];
|
[postComment setBodyHTML:bodyHTML];
|
||||||
|
|
||||||
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO];
|
[[self delegate] respondToStyleChange];
|
||||||
|
|
||||||
[sender setEnabled:YES];
|
[data[@"sender"] setEnabled:YES];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
@ -196,4 +161,3 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#import "Antenna.h"
|
#import "Antenna.h"
|
||||||
#import "assets/MMMarkdown.h"
|
#import "assets/TFHelper.h"
|
||||||
|
#import "assets/MMMarkdown/MMMarkdown.h"
|
||||||
|
|
||||||
static BOOL isAntennaEnabled;
|
static BOOL isAntennaEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -48,37 +49,18 @@ id tfAntennaCommentCell;
|
|||||||
%new
|
%new
|
||||||
-(void) handleUndeleteCommentAction{
|
-(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 comment = [tfAntennaCommentCell comment];
|
||||||
id commentText = [comment commentText];
|
id commentText = [comment commentText];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
NSString *body = data[@"body"];
|
||||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
|
||||||
|
|
||||||
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment itemId]]]];
|
[comment setAuthor:data[@"author"]];
|
||||||
[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];
|
|
||||||
[commentText setBody:body];
|
[commentText setBody:body];
|
||||||
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
|
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
|
||||||
|
|
||||||
@ -87,9 +69,8 @@ id tfAntennaCommentCell;
|
|||||||
[commentText setTextHeightCache:nil];
|
[commentText setTextHeightCache:nil];
|
||||||
[self setCommentHeightCache:nil];
|
[self setCommentHeightCache:nil];
|
||||||
|
|
||||||
[tfAntennaCommentCell performSelectorOnMainThread:@selector(updateWithModelObject:) withObject:comment waitUntilDone:YES];
|
[tfAntennaCommentCell updateWithModelObject:comment];
|
||||||
[[[self delegate] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
|
[[[self delegate] tableView] reloadData];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
@ -178,37 +159,18 @@ id tfAntennaCommentCell;
|
|||||||
|
|
||||||
[sender setEnabled:NO];
|
[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 post = [self post];
|
||||||
id postText = [post selfCommentText];
|
id postText = [post selfCommentText];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
NSString *body = data[@"body"];
|
||||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
|
||||||
|
|
||||||
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[post itemId]]]];
|
[post setAuthor:data[@"author"]];
|
||||||
[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];
|
|
||||||
[postText setBody:body];
|
[postText setBody:body];
|
||||||
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
|
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
|
||||||
|
|
||||||
@ -216,11 +178,10 @@ id tfAntennaCommentCell;
|
|||||||
[postText setBodyAttributedStringForPreview:nil];
|
[postText setBodyAttributedStringForPreview:nil];
|
||||||
[postText setTextHeightCache:nil];
|
[postText setTextHeightCache:nil];
|
||||||
|
|
||||||
[self performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
|
[self loadView];
|
||||||
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
|
[[self tableView] reloadData];
|
||||||
|
|
||||||
[sender setEnabled:YES];
|
[data[@"sender"] setEnabled:YES];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
181
tweak/Apollo.xm
181
tweak/Apollo.xm
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#import "Apollo.h"
|
#import "Apollo.h"
|
||||||
|
#import "assets/TFHelper.h"
|
||||||
|
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
static BOOL isApolloEnabled;
|
static BOOL isApolloEnabled;
|
||||||
@ -38,59 +39,6 @@ NSDictionary* apolloBodyAttributes = nil;
|
|||||||
%hook ApolloCommentCellNode
|
%hook ApolloCommentCellNode
|
||||||
%property(strong,nonatomic) id undeleteButton;
|
%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 {
|
-(void) didLoad {
|
||||||
%orig;
|
%orig;
|
||||||
|
|
||||||
@ -128,71 +76,49 @@ NSDictionary* apolloBodyAttributes = nil;
|
|||||||
CGFloat nodeSpacing =[ageNode frame].origin.x - nodeFrame.origin.x - nodeFrame.size.width;
|
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)];
|
[[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
|
%end
|
||||||
|
|
||||||
|
|
||||||
%hook ApolloCommentsHeaderCellNode
|
%hook ApolloCommentsHeaderCellNode
|
||||||
%property(strong, nonatomic) id undeleteButton;
|
%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{
|
-(void) didLoad{
|
||||||
%orig;
|
%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
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#import "BaconReader.h"
|
#import "BaconReader.h"
|
||||||
#import "assets/MMMarkdown.h"
|
#import "assets/TFHelper.h"
|
||||||
|
#import "assets/MMMarkdown/MMMarkdown.h"
|
||||||
|
|
||||||
static BOOL isBaconReaderEnabled;
|
static BOOL isBaconReaderEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -126,36 +127,17 @@ id tfStoryController;
|
|||||||
%new
|
%new
|
||||||
-(void) handleUndeleteCommentAction{
|
-(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];
|
id comment = [tfCommentCellView comment];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
NSString *body = data[@"body"];
|
||||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
|
||||||
|
|
||||||
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", [comment serverID]]]];
|
[comment setAuthor:data[@"author"]];
|
||||||
[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 setBody:body];
|
[comment setBody:body];
|
||||||
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
|
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
|
||||||
[comment setAttributedDescriptionString:nil];
|
[comment setAttributedDescriptionString:nil];
|
||||||
@ -163,48 +145,22 @@ id tfStoryController;
|
|||||||
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment];
|
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment];
|
||||||
[comment setAttributedDescriptionString:commentAttrString];
|
[comment setAttributedDescriptionString:commentAttrString];
|
||||||
|
|
||||||
[[[self detailPage] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
|
[[[self detailPage] tableView] reloadData];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%new
|
%new
|
||||||
-(void) handleUndeletePostAction{
|
-(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];
|
%new
|
||||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
-(void) completeUndeletePostAction:(NSDictionary *) data{
|
||||||
|
|
||||||
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", [post serverID]]]];
|
tfPostAuthor = data[@"author"];
|
||||||
[request setHTTPMethod:@"GET"];
|
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
|
||||||
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
|
|
||||||
|
|
||||||
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
|
[[self detailPage] refreshTouched];
|
||||||
|
|
||||||
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];
|
|
||||||
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#import "Beam.h"
|
#import "Beam.h"
|
||||||
|
#import "assets/TFHelper.h"
|
||||||
|
|
||||||
static BOOL isBeamEnabled;
|
static BOOL isBeamEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -25,8 +26,6 @@ static CGFloat pushshiftRequestTimeoutValue;
|
|||||||
|
|
||||||
NSString *commentBody = [[self comment] content];
|
NSString *commentBody = [[self comment] content];
|
||||||
|
|
||||||
HBLogDebug(@"body: %@", commentBody);
|
|
||||||
|
|
||||||
if ((isTFDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isTFDeletedOnly){
|
if ((isTFDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isTFDeletedOnly){
|
||||||
|
|
||||||
CGFloat authorTextHeight = [[self authorButton] frame].size.height;
|
CGFloat authorTextHeight = [[self authorButton] frame].size.height;
|
||||||
@ -51,45 +50,23 @@ static CGFloat pushshiftRequestTimeoutValue;
|
|||||||
|
|
||||||
[sender setEnabled:NO];
|
[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];
|
id comment = [self comment];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[comment setAuthor:data[@"author"]];
|
||||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
[comment setContent:data[@"body"]];
|
||||||
|
|
||||||
[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 setMarkdownString:nil];
|
[comment setMarkdownString:nil];
|
||||||
|
|
||||||
[self setCommentDidChange:YES];
|
[self setCommentDidChange:YES];
|
||||||
[self performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES];
|
[self reloadContents];
|
||||||
[[MSHookIvar<id>(self, "delegate") tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
|
[[MSHookIvar<id>(self, "delegate") tableView] reloadData];
|
||||||
|
|
||||||
[sender setEnabled:YES];
|
[data[@"sender"] setEnabled:YES];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
@ -174,50 +151,30 @@ static CGFloat pushshiftRequestTimeoutValue;
|
|||||||
|
|
||||||
if (post){
|
if (post){
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[post identifier] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
|
||||||
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]];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[post setAuthor:author];
|
%new
|
||||||
[post setContent:body];
|
-(void) completeUndeletePostAction:(NSDictionary *) data{
|
||||||
|
|
||||||
|
id post = [self post];
|
||||||
|
|
||||||
|
[post setAuthor:data[@"author"]];
|
||||||
|
[post setContent:data[@"body"]];
|
||||||
[post setMarkdownString:nil];
|
[post setMarkdownString:nil];
|
||||||
|
|
||||||
if ([self selfTextView]){
|
if ([self selfTextView]){
|
||||||
[[self selfTextView] performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES];
|
[[self selfTextView] reloadContents];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([self metadataView]){
|
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
|
%end
|
||||||
@ -274,4 +231,3 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
139
tweak/Narwhal.xm
139
tweak/Narwhal.xm
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#import "Narwhal.h"
|
#import "Narwhal.h"
|
||||||
|
#import "assets/TFHelper.h"
|
||||||
|
|
||||||
static BOOL isNarwhalEnabled;
|
static BOOL isNarwhalEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -12,37 +13,7 @@ id tfComment;
|
|||||||
id tfController;
|
id tfController;
|
||||||
|
|
||||||
void getUndeleteCommentData(id controller, id comment){
|
void getUndeleteCommentData(id controller, id comment){
|
||||||
|
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"comment" : comment} completionTarget:controller completionSelector:@selector(completeUndeleteCommentAction:)];
|
||||||
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];
|
|
||||||
}];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -61,7 +32,6 @@ void getUndeleteCommentData(id controller, id comment){
|
|||||||
}
|
}
|
||||||
|
|
||||||
[arg1 addAction:undeleteAction];
|
[arg1 addAction:undeleteAction];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%orig;
|
%orig;
|
||||||
@ -72,70 +42,6 @@ void getUndeleteCommentData(id controller, id comment){
|
|||||||
|
|
||||||
%hook NRTLinkViewController
|
%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{
|
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
|
||||||
|
|
||||||
if (arg2 == 2){
|
if (arg2 == 2){
|
||||||
@ -174,13 +80,29 @@ void getUndeleteCommentData(id controller, id comment){
|
|||||||
shouldHaveUndeleteAction = NO;
|
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
|
%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"];
|
id comment = data[@"comment"];
|
||||||
|
|
||||||
@ -193,6 +115,11 @@ void getUndeleteCommentData(id controller, id comment){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%end
|
||||||
|
|
||||||
|
|
||||||
|
%hook NRTMediaTableViewDataSource
|
||||||
|
|
||||||
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
|
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
|
||||||
|
|
||||||
if (arg2 == 2){
|
if (arg2 == 2){
|
||||||
@ -213,6 +140,20 @@ void getUndeleteCommentData(id controller, id comment){
|
|||||||
shouldHaveUndeleteAction = NO;
|
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
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
-(void) reloadPostSection:(BOOL) arg1;
|
-(void) reloadPostSection:(BOOL) arg1;
|
||||||
-(void) feedPostViewDidUpdatePost:(id) arg1 shouldReloadFeed:(BOOL) arg2;
|
-(void) feedPostViewDidUpdatePost:(id) arg1 shouldReloadFeed:(BOOL) arg2;
|
||||||
-(void) updateFloatingViews;
|
-(void) updateFloatingViews;
|
||||||
|
|
||||||
|
//custom elements
|
||||||
|
-(void) updateComments;
|
||||||
|
-(void) updatePostText;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface CommentActionSheetViewController : UIViewController
|
@interface CommentActionSheetViewController : UIViewController
|
||||||
|
251
tweak/Reddit.xm
251
tweak/Reddit.xm
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#import "Reddit.h"
|
#import "Reddit.h"
|
||||||
|
#import "assets/TFHelper.h"
|
||||||
|
|
||||||
static BOOL isRedditEnabled;
|
static BOOL isRedditEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -94,32 +95,18 @@ int getRedditVersionPart(int index){
|
|||||||
id commentTreeNode = [self commentTreeNode];
|
id commentTreeNode = [self commentTreeNode];
|
||||||
Comment *comment = [commentTreeNode comment];
|
Comment *comment = [commentTreeNode comment];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
|
||||||
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]];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
|
||||||
|
|
||||||
|
id commentTreeNode = [self commentTreeNode];
|
||||||
|
Comment *comment = [commentTreeNode comment];
|
||||||
|
|
||||||
|
NSString *author = data[@"author"];
|
||||||
|
NSString *body = data[@"body"];
|
||||||
|
|
||||||
NSMutableAttributedString *bodyMutableAttributedText;
|
NSMutableAttributedString *bodyMutableAttributedText;
|
||||||
|
|
||||||
@ -176,15 +163,11 @@ int getRedditVersionPart(int index){
|
|||||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
|
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
|
||||||
[comment setBodyAttributedText:bodyMutableAttributedText];
|
[comment setBodyAttributedText:bodyMutableAttributedText];
|
||||||
|
|
||||||
[[commentTreeNode commentTreeHeaderNode] performSelectorOnMainThread:@selector(updateContentViewsForData:) withObject:comment waitUntilDone:NO];
|
[[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
|
||||||
|
|
||||||
[request release];
|
|
||||||
[queue release];
|
|
||||||
[bodyMutableAttributedText release];
|
[bodyMutableAttributedText release];
|
||||||
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
|
||||||
|
|
||||||
@ -242,32 +225,17 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
if ([post isSelfPost]){
|
if ([post isSelfPost]){
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
|
||||||
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]];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) completeUndeletePostAction:(NSDictionary *) data{
|
||||||
|
Post *post = [self post];
|
||||||
|
|
||||||
|
NSString *author = data[@"author"];
|
||||||
|
NSString *body = data[@"body"];
|
||||||
|
|
||||||
id themeManager;
|
id themeManager;
|
||||||
id isNightMode;
|
id isNightMode;
|
||||||
@ -331,13 +299,9 @@ int getRedditVersionPart(int index){
|
|||||||
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
|
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
|
||||||
}
|
}
|
||||||
|
|
||||||
[request release];
|
|
||||||
[queue release];
|
|
||||||
[bodyMutableAttributedText release];
|
[bodyMutableAttributedText release];
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
|
||||||
%end
|
%end
|
||||||
@ -405,46 +369,7 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
Comment *comment = [self comment];
|
Comment *comment = [self comment];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
|
||||||
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];
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,36 +383,20 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
Comment *comment = [self comment];
|
Comment *comment = [self comment];
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
|
||||||
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]];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
|
||||||
|
|
||||||
|
Comment *comment = [self comment];
|
||||||
|
|
||||||
|
NSString *body = data[@"body"];
|
||||||
|
|
||||||
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
|
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
|
||||||
|
|
||||||
[comment setAuthor:author];
|
[comment setAuthor:data[@"author"]];
|
||||||
[comment setBodyText:body];
|
[comment setBodyText:body];
|
||||||
[comment setBodyAttributedText:bodyMutableAttributedText];
|
[comment setBodyAttributedText:bodyMutableAttributedText];
|
||||||
|
|
||||||
@ -495,13 +404,9 @@ int getRedditVersionPart(int index){
|
|||||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
|
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
|
[[self commentActionSheetDelegate] updateComments];
|
||||||
|
|
||||||
[request release];
|
|
||||||
[queue release];
|
|
||||||
[bodyMutableAttributedText release];
|
[bodyMutableAttributedText release];
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
|
||||||
@ -552,46 +457,7 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
if ([post isSelfPost]){
|
if ([post isSelfPost]){
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
|
||||||
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];
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,36 +474,21 @@ int getRedditVersionPart(int index){
|
|||||||
|
|
||||||
if ([post isSelfPost]){
|
if ([post isSelfPost]){
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
|
||||||
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]];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) completeUndeletePostAction:(NSDictionary *) data{
|
||||||
|
|
||||||
|
Post *post = [self post];
|
||||||
|
|
||||||
|
NSString *body = data[@"body"];
|
||||||
|
|
||||||
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
|
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
|
||||||
|
|
||||||
[post setAuthor:author];
|
[post setAuthor:data[@"author"]];
|
||||||
[post setSelfText:body];
|
[post setSelfText:body];
|
||||||
[post setSelfTextAttributed:bodyMutableAttributedText];
|
[post setSelfTextAttributed:bodyMutableAttributedText];
|
||||||
|
|
||||||
@ -649,15 +500,11 @@ int getRedditVersionPart(int index){
|
|||||||
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
|
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
|
[[self postActionSheetDelegate] updatePostText];
|
||||||
|
|
||||||
[request release];
|
|
||||||
[queue release];
|
|
||||||
[bodyMutableAttributedText release];
|
[bodyMutableAttributedText release];
|
||||||
}];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#import "Slide.h"
|
#import "Slide.h"
|
||||||
#import "assets/MMMarkdown.h"
|
#import "assets/TFHelper.h"
|
||||||
|
#import "assets/MMMarkdown/MMMarkdown.h"
|
||||||
|
|
||||||
static BOOL isSlideEnabled;
|
static BOOL isSlideEnabled;
|
||||||
static BOOL isTFDeletedOnly;
|
static BOOL isTFDeletedOnly;
|
||||||
@ -289,36 +290,20 @@ static UIButton * createUndeleteButton(){
|
|||||||
|
|
||||||
[sender setEnabled:NO];
|
[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];
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
||||||
id textStackDisplayView = MSHookIvar<id>(self, "commentBody");
|
id textStackDisplayView = MSHookIvar<id>(self, "commentBody");
|
||||||
id comment = MSHookIvar<id>(self, "comment");
|
id comment = MSHookIvar<id>(self, "comment");
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
NSString *author = data[@"author"];
|
||||||
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 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]];
|
|
||||||
}
|
|
||||||
|
|
||||||
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
|
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
|
||||||
|
|
||||||
@ -406,11 +391,10 @@ static UIButton * createUndeleteButton(){
|
|||||||
|
|
||||||
id controller = MSHookIvar<id>(self, "parent");
|
id controller = MSHookIvar<id>(self, "parent");
|
||||||
|
|
||||||
[self performSelectorOnMainThread:@selector(showMenu:) withObject:nil waitUntilDone:YES];
|
[self showMenu:nil];
|
||||||
[MSHookIvar<id>(controller, "tableView") performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
|
[MSHookIvar<id>(controller, "tableView") reloadData];
|
||||||
|
|
||||||
[sender setEnabled:YES];
|
[data[@"sender"] setEnabled:YES];
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
6
tweak/assets/TFHelper.h
Normal file
6
tweak/assets/TFHelper.h
Normal 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
50
tweak/assets/TFHelper.m
Normal 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
|
Reference in New Issue
Block a user