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 |
#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; | ||||
id comment = [[self node] comment]; | id comment = [[self node] 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 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:@"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]; | |||||
[comment setAuthor:author]; | |||||
[comment setBody:body]; | |||||
[comment setBodyHTML:bodyHTML]; | |||||
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO]; | |||||
[sender setEnabled:YES]; | |||||
}]; | |||||
[%c(TFHelper) getUndeleteDataWithID:[comment ident] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)]; | |||||
} | |||||
%new | |||||
-(void) completeUndeleteCommentAction:(NSDictionary *) data{ | |||||
id comment = [[self node] comment]; | |||||
NSString *body = data[@"body"]; | |||||
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]; | |||||
[comment setAuthor:data[@"author"]]; | |||||
[comment setBody:body]; | |||||
[comment setBodyHTML:bodyHTML]; | |||||
[[self delegate] respondToStyleChange]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | } | ||||
%new | %new | ||||
[sender setEnabled:NO]; | [sender setEnabled:NO]; | ||||
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 | |||||
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]; | |||||
[%c(TFHelper) getUndeleteDataWithID:[post ident] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; | |||||
} | |||||
[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]; | |||||
[post setAuthor:author]; | |||||
[post setSelftext:body]; | |||||
[postComment setBodyHTML:bodyHTML]; | |||||
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO]; | |||||
[sender setEnabled:YES]; | |||||
}]; | |||||
%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 | |||||
NSString *body = data[@"body"]; | |||||
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]; | |||||
[post setAuthor:data[@"author"]]; | |||||
[post setSelftext:body]; | |||||
[postComment setBodyHTML:bodyHTML]; | |||||
[[self delegate] respondToStyleChange]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | } | ||||
%end | %end | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#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; | ||||
%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]; | |||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |||||
[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 *body = data[@"body"]; | |||||
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 setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]]; | |||||
[commentText setBodyAttributedString:nil]; | |||||
[commentText setBodyAttributedStringForPreview:nil]; | |||||
[commentText setTextHeightCache:nil]; | |||||
[self setCommentHeightCache:nil]; | |||||
[tfAntennaCommentCell performSelectorOnMainThread:@selector(updateWithModelObject:) withObject:comment waitUntilDone:YES]; | |||||
[[[self delegate] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; | |||||
}]; | |||||
[comment setAuthor:data[@"author"]]; | |||||
[commentText setBody:body]; | |||||
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]]; | |||||
[commentText setBodyAttributedString:nil]; | |||||
[commentText setBodyAttributedStringForPreview:nil]; | |||||
[commentText setTextHeightCache:nil]; | |||||
[self setCommentHeightCache:nil]; | |||||
[tfAntennaCommentCell updateWithModelObject:comment]; | |||||
[[[self delegate] tableView] reloadData]; | |||||
} | } | ||||
%end | %end | ||||
[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]; | |||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |||||
[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]; | |||||
[postText setBody:body]; | |||||
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]]; | |||||
[postText setBodyAttributedString:nil]; | |||||
[postText setBodyAttributedStringForPreview:nil]; | |||||
[postText setTextHeightCache:nil]; | |||||
[self performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES]; | |||||
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; | |||||
[sender setEnabled:YES]; | |||||
}]; | |||||
NSString *body = data[@"body"]; | |||||
[post setAuthor:data[@"author"]]; | |||||
[postText setBody:body]; | |||||
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]]; | |||||
[postText setBodyAttributedString:nil]; | |||||
[postText setBodyAttributedStringForPreview:nil]; | |||||
[postText setTextHeightCache:nil]; | |||||
[self loadView]; | |||||
[[self tableView] reloadData]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | } | ||||
%end | %end |
#import "Apollo.h" | #import "Apollo.h" | ||||
#import "assets/TFHelper.h" | |||||
static BOOL isTFDeletedOnly; | static BOOL isTFDeletedOnly; | ||||
static BOOL isApolloEnabled; | static BOOL isApolloEnabled; | ||||
%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; | ||||
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)]; | ||||
} | } | ||||
} | } | ||||
%end | |||||
%hook ApolloCommentsHeaderCellNode | |||||
%property(strong, nonatomic) id undeleteButton; | |||||
%new | %new | ||||
-(void) didTapUndeleteButton:(id) sender{ | -(void) didTapUndeleteButton:(id) sender{ | ||||
[sender setEnabled:NO]; | [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 bodyNode = MSHookIvar<id>(self, "bodyNode"); | ||||
id postInfoNode = MSHookIvar<id>(self, "postInfoNode"); | |||||
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode"); | |||||
id authorNode = MSHookIvar<id>(self, "authorNode"); | |||||
id authorTextNode = [authorNode subnodes][0]; | 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]; | |||||
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]; | |||||
[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. | |||||
[authorTextNode setAttributedText:newAuthorAttributedString]; | |||||
[authorTextNode setAttributedString:newAuthorAttributedString]; | |||||
[comment setAuthor:author]; | |||||
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:data[@"body"] withAttributes:apolloBodyAttributes]]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | |||||
author = [NSString stringWithFormat:@"by %@", author]; | |||||
%end | |||||
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]; | |||||
}]; | |||||
} | |||||
%hook ApolloCommentsHeaderCellNode | |||||
%property(strong, nonatomic) id undeleteButton; | |||||
-(void) didLoad{ | -(void) didLoad{ | ||||
%orig; | %orig; | ||||
} | } | ||||
} | } | ||||
%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 |
#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; | ||||
%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]; | |||||
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |||||
[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 *body = data[@"body"]; | |||||
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_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]]; | |||||
[comment setAttributedDescriptionString:nil]; | |||||
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment]; | |||||
[comment setAttributedDescriptionString:commentAttrString]; | |||||
[[[self detailPage] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; | |||||
}]; | |||||
[comment setAuthor:data[@"author"]]; | |||||
[comment setBody:body]; | |||||
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]]; | |||||
[comment setAttributedDescriptionString:nil]; | |||||
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment]; | |||||
[comment setAttributedDescriptionString:commentAttrString]; | |||||
[[[self detailPage] tableView] reloadData]; | |||||
} | } | ||||
%new | %new | ||||
-(void) handleUndeletePostAction{ | -(void) handleUndeletePostAction{ | ||||
id post = [self story]; | |||||
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 serverID]]]]; | |||||
[request setHTTPMethod:@"GET"]; | |||||
[request setTimeoutInterval:pushshiftRequestTimeoutValue]; | |||||
[%c(TFHelper) getUndeleteDataWithID:[[self story] serverID] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; | |||||
} | |||||
[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]; | |||||
%new | |||||
-(void) completeUndeletePostAction:(NSDictionary *) data{ | |||||
[[self detailPage] performSelectorOnMainThread:@selector(refreshTouched) withObject:nil waitUntilDone:NO]; | |||||
}]; | |||||
tfPostAuthor = data[@"author"]; | |||||
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil]; | |||||
[[self detailPage] refreshTouched]; | |||||
} | } | ||||
%end | %end |
#import "Beam.h" | #import "Beam.h" | ||||
#import "assets/TFHelper.h" | |||||
static BOOL isBeamEnabled; | static BOOL isBeamEnabled; | ||||
static BOOL isTFDeletedOnly; | static BOOL isTFDeletedOnly; | ||||
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; | ||||
[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]; | |||||
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 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]; | |||||
[sender setEnabled:YES]; | |||||
}]; | |||||
[comment setAuthor:data[@"author"]]; | |||||
[comment setContent:data[@"body"]]; | |||||
[comment setMarkdownString:nil]; | |||||
[self setCommentDidChange:YES]; | |||||
[self reloadContents]; | |||||
[[MSHookIvar<id>(self, "delegate") tableView] reloadData]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | } | ||||
%end | %end | ||||
id post = [self post]; | id post = [self post]; | ||||
if (post){ | if (post){ | ||||
[%c(TFHelper) getUndeleteDataWithID:[post identifier] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; | |||||
} | |||||
} | |||||
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]]; | |||||
} | |||||
[post setAuthor:author]; | |||||
[post setContent:body]; | |||||
[post setMarkdownString:nil]; | |||||
if ([self selfTextView]){ | |||||
[[self selfTextView] performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES]; | |||||
} | |||||
if ([self metadataView]){ | |||||
[[self metadataView] performSelectorOnMainThread:@selector(setPost:) withObject:post waitUntilDone:YES]; | |||||
} | |||||
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:post waitUntilDone:NO]; | |||||
[sender setEnabled:YES]; | |||||
}]; | |||||
%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] reloadContents]; | |||||
} | } | ||||
if ([self metadataView]){ | |||||
[[self metadataView] setPost:post]; | |||||
} | |||||
[[self tableView] reloadData]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | } | ||||
%end | %end | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#import "Narwhal.h" | #import "Narwhal.h" | ||||
#import "assets/TFHelper.h" | |||||
static BOOL isNarwhalEnabled; | static BOOL isNarwhalEnabled; | ||||
static BOOL isTFDeletedOnly; | static BOOL isTFDeletedOnly; | ||||
id tfComment; | id tfComment; | ||||
id tfController; | 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]; | |||||
}]; | |||||
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:)]; | |||||
} | } | ||||
} | } | ||||
[arg1 addAction:undeleteAction]; | [arg1 addAction:undeleteAction]; | ||||
} | } | ||||
%orig; | %orig; | ||||
%end | %end | ||||
%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]; | |||||
}]; | |||||
} | |||||
%hook NRTLinkViewController | |||||
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{ | -(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{ | ||||
shouldHaveUndeleteAction = NO; | shouldHaveUndeleteAction = NO; | ||||
} | } | ||||
%end | |||||
%new | |||||
-(void) handleUndeletePostAction{ | |||||
id post = [self link]; | |||||
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"post" : post} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; | |||||
} | |||||
%new | |||||
-(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"]; | |||||
if (comment){ | |||||
%hook NRTMediaTableViewDataSource | |||||
%new | |||||
-(void) completeUndeleteComment:(id) data{ | |||||
id comment = data[@"comment"]; | |||||
if (comment){ | |||||
MSHookIvar<NSString*>(comment, "_author") = data[@"author"]; | MSHookIvar<NSString*>(comment, "_author") = data[@"author"]; | ||||
MSHookIvar<NSString*>(comment, "_body") = data[@"body"]; | MSHookIvar<NSString*>(comment, "_body") = data[@"body"]; | ||||
[[self commentsManager] updateComment:comment fromEdited:comment]; | |||||
} | |||||
[[self commentsManager] updateComment:comment fromEdited:comment]; | |||||
} | |||||
} | } | ||||
%end | |||||
%hook NRTMediaTableViewDataSource | |||||
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{ | -(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{ | ||||
if (arg2 == 2){ | if (arg2 == 2){ | ||||
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 |
-(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 |
#import "Reddit.h" | #import "Reddit.h" | ||||
#import "assets/TFHelper.h" | |||||
static BOOL isRedditEnabled; | static BOOL isRedditEnabled; | ||||
static BOOL isTFDeletedOnly; | static BOOL isTFDeletedOnly; | ||||
id commentTreeNode = [self commentTreeNode]; | id commentTreeNode = [self commentTreeNode]; | ||||
Comment *comment = [commentTreeNode comment]; | Comment *comment = [commentTreeNode comment]; | ||||
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self 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 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; | |||||
id themeManager; | |||||
id isNightMode; | |||||
id textColor; | |||||
if (getRedditVersionPart(1) >= 45){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager darkTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager lightTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else if (getRedditVersionPart(1) >= 37){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else { | |||||
themeManager = [%c(ThemeManager) sharedManager]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
} | |||||
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; | |||||
[bodyMutableAttributedText beginEditing]; | |||||
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { | |||||
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range]; | |||||
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range]; | |||||
}]; | |||||
[bodyMutableAttributedText endEditing]; | |||||
[comment setAuthor:author]; | |||||
[comment setBodyText:body]; | |||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText]; | |||||
[comment setBodyAttributedText:bodyMutableAttributedText]; | |||||
[[commentTreeNode commentTreeHeaderNode] performSelectorOnMainThread:@selector(updateContentViewsForData:) withObject:comment waitUntilDone:NO]; | |||||
[request release]; | |||||
[queue release]; | |||||
[bodyMutableAttributedText release]; | |||||
%new | |||||
-(void) completeUndeleteCommentAction:(NSDictionary *) data{ | |||||
id commentTreeNode = [self commentTreeNode]; | |||||
Comment *comment = [commentTreeNode comment]; | |||||
NSString *author = data[@"author"]; | |||||
NSString *body = data[@"body"]; | |||||
NSMutableAttributedString *bodyMutableAttributedText; | |||||
}]; | |||||
id themeManager; | |||||
id isNightMode; | |||||
id textColor; | |||||
if (getRedditVersionPart(1) >= 45){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager darkTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager lightTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else if (getRedditVersionPart(1) >= 37){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else { | |||||
themeManager = [%c(ThemeManager) sharedManager]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
} | } | ||||
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; | |||||
[bodyMutableAttributedText beginEditing]; | |||||
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { | |||||
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range]; | |||||
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range]; | |||||
}]; | |||||
[bodyMutableAttributedText endEditing]; | |||||
[comment setAuthor:author]; | |||||
[comment setBodyText:body]; | |||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText]; | |||||
[comment setBodyAttributedText:bodyMutableAttributedText]; | |||||
[[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment]; | |||||
[bodyMutableAttributedText release]; | |||||
} | } | ||||
%end | %end | ||||
if ([post isSelfPost]){ | 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]]; | |||||
} | |||||
id themeManager; | |||||
id isNightMode; | |||||
id textColor; | |||||
if (getRedditVersionPart(1) >= 45){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager darkTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager lightTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else if (getRedditVersionPart(1) >= 37){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else { | |||||
themeManager = [%c(ThemeManager) sharedManager]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
} | |||||
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; | |||||
[bodyMutableAttributedText beginEditing]; | |||||
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { | |||||
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range]; | |||||
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range]; | |||||
}]; | |||||
[bodyMutableAttributedText endEditing]; | |||||
[post setSelfText:body]; | |||||
[post setAuthor:author]; | |||||
[post setSelfPostRichTextAttributed:bodyMutableAttributedText]; | |||||
[post setPreviewFeedPostTextString:bodyMutableAttributedText]; | |||||
if (getRedditVersionPart(1) >= 44){ | |||||
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode]; | |||||
} else if (getRedditVersionPart(1) >= 38) { | |||||
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode]; | |||||
} else { | |||||
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode]; | |||||
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes]; | |||||
} | |||||
[request release]; | |||||
[queue release]; | |||||
[bodyMutableAttributedText release]; | |||||
}]; | |||||
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
%new | |||||
-(void) completeUndeletePostAction:(NSDictionary *) data{ | |||||
Post *post = [self post]; | |||||
NSString *author = data[@"author"]; | |||||
NSString *body = data[@"body"]; | |||||
id themeManager; | |||||
id isNightMode; | |||||
id textColor; | |||||
if (getRedditVersionPart(1) >= 45){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager darkTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager lightTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else if (getRedditVersionPart(1) >= 37){ | |||||
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
[themeManager release]; | |||||
} else { | |||||
themeManager = [%c(ThemeManager) sharedManager]; | |||||
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; | |||||
if (isNightMode) { | |||||
textColor = [[themeManager nightTheme] bodyTextColor]; | |||||
} else{ | |||||
textColor = [[themeManager dayTheme] bodyTextColor]; | |||||
} | |||||
} | |||||
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; | |||||
[bodyMutableAttributedText beginEditing]; | |||||
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) { | |||||
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range]; | |||||
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range]; | |||||
}]; | |||||
[bodyMutableAttributedText endEditing]; | |||||
[post setSelfText:body]; | |||||
[post setAuthor:author]; | |||||
[post setSelfPostRichTextAttributed:bodyMutableAttributedText]; | |||||
[post setPreviewFeedPostTextString:bodyMutableAttributedText]; | |||||
if (getRedditVersionPart(1) >= 44){ | |||||
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode]; | |||||
} else if (getRedditVersionPart(1) >= 38) { | |||||
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode]; | |||||
} else { | |||||
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode]; | |||||
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes]; | |||||
} | |||||
[bodyMutableAttributedText release]; | |||||
} | |||||
%end | %end | ||||
%end | %end | ||||
[self dismissViewControllerAnimated:YES completion:nil]; | [self dismissViewControllerAnimated:YES completion:nil]; | ||||
Comment *comment = [self comment]; | 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:)]; | |||||
} | } | ||||
} | } | ||||
[self dismissViewControllerAnimated:YES completion:nil]; | [self dismissViewControllerAnimated:YES completion:nil]; | ||||
Comment *comment = [self comment]; | Comment *comment = [self comment]; | ||||
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self 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 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 setBodyAttributedText:bodyMutableAttributedText]; | |||||
if (getRedditVersionPart(1) >= 12) { | |||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText]; | |||||
} | |||||
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO]; | |||||
%new | |||||
-(void) completeUndeleteCommentAction:(NSDictionary *) data{ | |||||
Comment *comment = [self comment]; | |||||
NSString *body = data[@"body"]; | |||||
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; | |||||
[comment setAuthor:data[@"author"]]; | |||||
[comment setBodyText:body]; | |||||
[comment setBodyAttributedText:bodyMutableAttributedText]; | |||||
[request release]; | |||||
[queue release]; | |||||
[bodyMutableAttributedText release]; | |||||
}]; | |||||
if (getRedditVersionPart(1) >= 12) { | |||||
[comment setBodyRichTextAttributed:bodyMutableAttributedText]; | |||||
} | } | ||||
[[self commentActionSheetDelegate] updateComments]; | |||||
[bodyMutableAttributedText release]; | |||||
} | } | ||||
%end | %end | ||||
if ([post isSelfPost]){ | 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:)]; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if ([post isSelfPost]){ | 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 setAuthor:author]; | |||||
[post setSelfText:body]; | |||||
[post setSelfTextAttributed:bodyMutableAttributedText]; | |||||
if (getRedditVersionPart(1) >= 8) { | |||||
[post setSelfPostRichTextAttributed:bodyMutableAttributedText]; | |||||
} | |||||
if (getRedditVersionPart(1) >= 15) { | |||||
[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:)]; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
%new | |||||
-(void) completeUndeletePostAction:(NSDictionary *) data{ | |||||
Post *post = [self post]; | |||||
NSString *body = data[@"body"]; | |||||
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; | |||||
[post setAuthor:data[@"author"]]; | |||||
[post setSelfText:body]; | |||||
[post setSelfTextAttributed:bodyMutableAttributedText]; | |||||
if (getRedditVersionPart(1) >= 8) { | |||||
[post setSelfPostRichTextAttributed:bodyMutableAttributedText]; | |||||
} | |||||
if (getRedditVersionPart(1) >= 15) { | |||||
[post setPreviewFeedPostTextString:bodyMutableAttributedText]; | |||||
} | |||||
[[self postActionSheetDelegate] updatePostText]; | |||||
[bodyMutableAttributedText release]; | |||||
} | |||||
%end | %end | ||||
%end | %end |
#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; | ||||
-(void) handleUndeleteComment:(id) sender{ | -(void) handleUndeleteComment:(id) sender{ | ||||
[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]; | |||||
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 = data[@"author"]; | |||||
NSString *body = data[@"body"]; | |||||
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(...) | |||||
UIFont *font = [%c(FontGenerator) fontOfSize:MSHookIvar<CGFloat>(textStackDisplayView, "fontSize") submission:NO willOffset:YES]; | |||||
UIFont *font = [%c(FontGenerator) fontOfSize:MSHookIvar<CGFloat>(textStackDisplayView, "fontSize") submission:NO willOffset:YES]; | |||||
NSString *themeName = [userDefaults stringForKey:@"theme"]; | |||||
UIColor *fontColor = [%c(ColorUtil) fontColorForTheme:themeName]; | |||||
UIColor *accentColor = [%c(ColorUtil) accentColorForSub:[comment subreddit]]; | |||||
NSString *html = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]; | |||||
html = [[html stringByReplacingOccurrencesOfString:@"<sup>" withString:@"<font size=\"1\">"] stringByReplacingOccurrencesOfString:@"</sup>" withString:@"</font>"]; | |||||
html = [[html stringByReplacingOccurrencesOfString:@"<del>" withString:@"<font color=\"green\">"] stringByReplacingOccurrencesOfString:@"</del>" withString:@"</font>"]; | |||||
html = [[html stringByReplacingOccurrencesOfString:@"<code>" withString:@"<font color=\"blue\">"] stringByReplacingOccurrencesOfString:@"</code>" withString:@"</font>"]; | |||||
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |||||
DTHTMLAttributedStringBuilder *dthtmlBuilder = [[%c(DTHTMLAttributedStringBuilder) alloc] initWithHTML:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{@"DTUseiOS6Attributes": @YES, @"DTDefaultTextColor": fontColor, @"DTDefaultFontSize": @([font pointSize])} documentAttributes:nil]; | |||||
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[dthtmlBuilder generatedAttributedString]]; | |||||
NSRange htmlStringRange = NSMakeRange(0, [htmlAttributedString length]); | |||||
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t•\t" withString:@" • " options:0 range: htmlStringRange]; | |||||
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t◦\t" withString:@" ◦ " options:0 range: htmlStringRange]; | |||||
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t▪\t" withString:@" ▪ " options:0 range: htmlStringRange]; | |||||
[htmlAttributedString removeAttribute:@"CTForegroundColorFromContext" range:htmlStringRange]; | |||||
[htmlAttributedString enumerateAttributesInRange:htmlStringRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) { | |||||
for (NSString *key in attributes){ | |||||
NSString *themeName = [userDefaults stringForKey:@"theme"]; | |||||
UIColor *fontColor = [%c(ColorUtil) fontColorForTheme:themeName]; | |||||
UIColor *accentColor = [%c(ColorUtil) accentColorForSub:[comment subreddit]]; | |||||
NSString *html = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]; | |||||
html = [[html stringByReplacingOccurrencesOfString:@"<sup>" withString:@"<font size=\"1\">"] stringByReplacingOccurrencesOfString:@"</sup>" withString:@"</font>"]; | |||||
html = [[html stringByReplacingOccurrencesOfString:@"<del>" withString:@"<font color=\"green\">"] stringByReplacingOccurrencesOfString:@"</del>" withString:@"</font>"]; | |||||
html = [[html stringByReplacingOccurrencesOfString:@"<code>" withString:@"<font color=\"blue\">"] stringByReplacingOccurrencesOfString:@"</code>" withString:@"</font>"]; | |||||
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |||||
DTHTMLAttributedStringBuilder *dthtmlBuilder = [[%c(DTHTMLAttributedStringBuilder) alloc] initWithHTML:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{@"DTUseiOS6Attributes": @YES, @"DTDefaultTextColor": fontColor, @"DTDefaultFontSize": @([font pointSize])} documentAttributes:nil]; | |||||
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[dthtmlBuilder generatedAttributedString]]; | |||||
NSRange htmlStringRange = NSMakeRange(0, [htmlAttributedString length]); | |||||
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t•\t" withString:@" • " options:0 range: htmlStringRange]; | |||||
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t◦\t" withString:@" ◦ " options:0 range: htmlStringRange]; | |||||
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t▪\t" withString:@" ▪ " options:0 range: htmlStringRange]; | |||||
[htmlAttributedString removeAttribute:@"CTForegroundColorFromContext" range:htmlStringRange]; | |||||
[htmlAttributedString enumerateAttributesInRange:htmlStringRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) { | |||||
for (NSString *key in attributes){ | |||||
if ([(UIColor *) attributes[key] isKindOfClass:[UIColor class]]){ | |||||
UIColor *attrColor = (UIColor *) attributes[key]; | |||||
if ([[attrColor hexString] isEqualToString:@"#0000FF"]){ | |||||
UIFont *tempFont = [UIFont fontWithName:@"Courier" size:font.pointSize]; | |||||
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: accentColor, NSBackgroundColorAttributeName: [%c(ColorUtil) backgroundColorForTheme:themeName], NSFontAttributeName: (tempFont ? tempFont : font)} range:range]; | |||||
} else if ([[attrColor hexString] isEqualToString:@"#008000"]) { | |||||
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: fontColor, NSFontAttributeName:font} range:range]; | |||||
} | |||||
} else if ([(NSURL *) attributes[key] isKindOfClass:[NSURL class]]){ | |||||
NSURL *attrUrl = (NSURL *)attributes[key]; | |||||
if (([userDefaults objectForKey:@"ENLARGE_LINKS"] == nil) ? YES : [userDefaults boolForKey:@"ENLARGE_LINKS"]){ | |||||
[htmlAttributedString addAttribute:NSFontAttributeName value:[%c(FontGenerator) boldFontOfSize:18 submission:NO willOffset:YES] range:range]; | |||||
} | |||||
if ([(UIColor *) attributes[key] isKindOfClass:[UIColor class]]){ | |||||
UIColor *attrColor = (UIColor *) attributes[key]; | |||||
if ([[attrColor hexString] isEqualToString:@"#0000FF"]){ | |||||
UIFont *tempFont = [UIFont fontWithName:@"Courier" size:font.pointSize]; | |||||
[htmlAttributedString addAttribute:NSForegroundColorAttributeName value:accentColor range:range]; | |||||
[htmlAttributedString addAttribute:NSUnderlineColorAttributeName value:[UIColor clearColor] range:range]; | |||||
//skipping showLinkContentType b/c not necessary and spoilers b/c MMMarkdown doesn't support them | |||||
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: accentColor, NSBackgroundColorAttributeName: [%c(ColorUtil) backgroundColorForTheme:themeName], NSFontAttributeName: (tempFont ? tempFont : font)} range:range]; | |||||
} else if ([[attrColor hexString] isEqualToString:@"#008000"]) { | |||||
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: fontColor, NSFontAttributeName:font} range:range]; | |||||
} | |||||
} else if ([(NSURL *) attributes[key] isKindOfClass:[NSURL class]]){ | |||||
NSURL *attrUrl = (NSURL *)attributes[key]; | |||||
[htmlAttributedString yy_setTextHighlightRange:range color: accentColor backgroundColor:nil userInfo:@{@"url": attrUrl}]; | |||||
break; | |||||
} | |||||
} | |||||
}]; | |||||
[htmlAttributedString beginEditing]; | |||||
[htmlAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, [htmlAttributedString length]) options:0 usingBlock:^(id value, NSRange range, BOOL *stop){ | |||||
UIFont *attrFont = (UIFont *)value; | |||||
BOOL isBold = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) != 0; | |||||
BOOL isItalic = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) != 0; | |||||
UIFont *newFont = font; | |||||
if (isBold){ | |||||
newFont = [%c(FontGenerator) boldFontOfSize:attrFont.pointSize submission:NO willOffset:NO]; | |||||
} else if (isItalic){ | |||||
newFont = [%c(FontGenerator) italicFontOfSize:attrFont.pointSize submission:NO willOffset:NO]; | |||||
} | |||||
[htmlAttributedString removeAttribute:NSFontAttributeName range:range]; | |||||
[htmlAttributedString addAttribute:NSFontAttributeName value:newFont range:range]; | |||||
}]; | |||||
[htmlAttributedString endEditing]; | |||||
NSMutableAttributedString *newCommentText = [MSHookIvar<NSMutableAttributedString *>(self, "cellContent") initWithAttributedString:htmlAttributedString]; | |||||
NSAttributedString *tempAttributedString = [[NSAttributedString alloc] initWithString:@""]; | |||||
[newCommentText appendAttributedString:tempAttributedString]; //to keep the compiler happy | |||||
if (([userDefaults objectForKey:@"ENLARGE_LINKS"] == nil) ? YES : [userDefaults boolForKey:@"ENLARGE_LINKS"]){ | |||||
[htmlAttributedString addAttribute:NSFontAttributeName value:[%c(FontGenerator) boldFontOfSize:18 submission:NO willOffset:YES] range:range]; | |||||
} | |||||
[htmlAttributedString addAttribute:NSForegroundColorAttributeName value:accentColor range:range]; | |||||
[htmlAttributedString addAttribute:NSUnderlineColorAttributeName value:[UIColor clearColor] range:range]; | |||||
//skipping showLinkContentType b/c not necessary and spoilers b/c MMMarkdown doesn't support them | |||||
[htmlAttributedString yy_setTextHighlightRange:range color: accentColor backgroundColor:nil userInfo:@{@"url": attrUrl}]; | |||||
break; | |||||
} | |||||
} | |||||
}]; | |||||
[htmlAttributedString beginEditing]; | |||||
[htmlAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, [htmlAttributedString length]) options:0 usingBlock:^(id value, NSRange range, BOOL *stop){ | |||||
[comment setAuthor:author]; | |||||
[comment setBody:body]; | |||||
UIFont *attrFont = (UIFont *)value; | |||||
id controller = MSHookIvar<id>(self, "parent"); | |||||
BOOL isBold = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) != 0; | |||||
BOOL isItalic = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) != 0; | |||||
[self performSelectorOnMainThread:@selector(showMenu:) withObject:nil waitUntilDone:YES]; | |||||
[MSHookIvar<id>(controller, "tableView") performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; | |||||
UIFont *newFont = font; | |||||
[sender setEnabled:YES]; | |||||
if (isBold){ | |||||
newFont = [%c(FontGenerator) boldFontOfSize:attrFont.pointSize submission:NO willOffset:NO]; | |||||
} else if (isItalic){ | |||||
newFont = [%c(FontGenerator) italicFontOfSize:attrFont.pointSize submission:NO willOffset:NO]; | |||||
} | |||||
[htmlAttributedString removeAttribute:NSFontAttributeName range:range]; | |||||
[htmlAttributedString addAttribute:NSFontAttributeName value:newFont range:range]; | |||||
}]; | }]; | ||||
[htmlAttributedString endEditing]; | |||||
NSMutableAttributedString *newCommentText = [MSHookIvar<NSMutableAttributedString *>(self, "cellContent") initWithAttributedString:htmlAttributedString]; | |||||
NSAttributedString *tempAttributedString = [[NSAttributedString alloc] initWithString:@""]; | |||||
[newCommentText appendAttributedString:tempAttributedString]; //to keep the compiler happy | |||||
[comment setAuthor:author]; | |||||
[comment setBody:body]; | |||||
id controller = MSHookIvar<id>(self, "parent"); | |||||
[self showMenu:nil]; | |||||
[MSHookIvar<id>(controller, "tableView") reloadData]; | |||||
[data[@"sender"] setEnabled:YES]; | |||||
} | } | ||||
%end | %end |
@interface TFHelper : NSObject | |||||
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel; | |||||
@end |
#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 |