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

Add request timeout, switch to Cephei prefs

This commit is contained in:
lint
2019-11-10 18:00:26 -05:00
parent f8dafd9467
commit bb602d1121
6 changed files with 105 additions and 59 deletions

View File

@ -5,6 +5,8 @@ include $(THEOS)/makefiles/common.mk
TWEAK_NAME = tfdidthatsay TWEAK_NAME = tfdidthatsay
tfdidthatsay_FILES = $(wildcard tweak/*.xm) tfdidthatsay_FILES = $(wildcard tweak/*.xm)
tweak/Narwhal.xm_CFLAGS = -fobjc-arc tweak/Narwhal.xm_CFLAGS = -fobjc-arc
tfdidthatsay_EXTRA_FRAMEWORKS += Cephei
include $(THEOS_MAKE_PATH)/tweak.mk include $(THEOS_MAKE_PATH)/tweak.mk

View File

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

View File

@ -22,6 +22,32 @@
<key>label</key> <key>label</key>
<string>Only display eye on deleted comments</string> <string>Only display eye on deleted comments</string>
</dict> </dict>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>footerText</key>
<string>The number of seconds before the request to pushshift will timeout and return an error.</string>
<key>isStaticText</key>
<true/>
<key>label</key>
<string>Request timeout (seconds)</string>
</dict>
<dict>
<key>cell</key>
<string>PSSliderCell</string>
<key>default</key>
<integer>10</integer>
<key>defaults</key>
<string>com.lint.undelete.prefs</string>
<key>key</key>
<string>requestTimeoutValue</string>
<key>max</key>
<string>60</string>
<key>min</key>
<string>5</string>
<key>showValue</key>
<true/>
</dict>
</array> </array>
<key>title</key> <key>title</key>
<string>TFDidThatSay?</string> <string>TFDidThatSay?</string>

View File

@ -1,9 +1,12 @@
#import <Cephei/HBPreferences.h>
#import "Apollo.h" #import "Apollo.h"
%group Apollo HBPreferences *apolloPrefs;
BOOL isApolloDeletedCommentsOnly;
CGFloat apolloRequestTimeoutValue;
const NSDictionary* settings = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.lint.undelete.prefs.plist"]; %group Apollo
NSDictionary* apolloBodyAttributes = nil; NSDictionary* apolloBodyAttributes = nil;
@ -51,6 +54,7 @@ NSDictionary* apolloBodyAttributes = nil;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[apolloPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -69,7 +73,7 @@ NSDictionary* apolloBodyAttributes = nil;
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
id prevAuthorAttributedString = [authorTextNode attributedString]; id prevAuthorAttributedString = [authorTextNode attributedString];
@ -93,9 +97,9 @@ NSDictionary* apolloBodyAttributes = nil;
id commentBody = [MSHookIvar<id>(self, "comment") body]; id commentBody = [MSHookIvar<id>(self, "comment") body];
id isDeletedOnly = [settings valueForKey:@"isApolloDeletedCommentsOnly"]; BOOL isDeletedOnly = [apolloPrefs boolForKey:@"isApolloDeletedCommentsOnly"];
if (([isDeletedOnly isEqual:@1] && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || [isDeletedOnly isEqual:@0] ) { if ((isDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isDeletedOnly) {
CGFloat imageSize = 20.0f; CGFloat imageSize = 20.0f;
@ -153,6 +157,7 @@ NSDictionary* apolloBodyAttributes = nil;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[apolloPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -171,7 +176,7 @@ NSDictionary* apolloBodyAttributes = nil;
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; 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. //MSHookIvar<NSString*>(post, "_author") = author; //Crashes when clicking on author name. You will have to search the author name to go find the profile.
@ -235,6 +240,10 @@ NSDictionary* apolloBodyAttributes = nil;
%ctor { %ctor {
apolloPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[apolloPrefs registerBool:&isApolloDeletedCommentsOnly default:YES forKey:@"isApolloDeletedCommentsOnly"];
[apolloPrefs registerDouble:&apolloRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
NSString* processName = [[NSProcessInfo processInfo] processName]; NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"Apollo"]){ if ([processName isEqualToString:@"Apollo"]){

View File

@ -1,6 +1,10 @@
#import <Cephei/HBPreferences.h>
#import "Narwhal.h" #import "Narwhal.h"
HBPreferences *narwhalPrefs;
CGFloat narwhalRequestTimeoutValue;
%group Narwhal %group Narwhal
BOOL shouldHaveUndeleteAction = NO; BOOL shouldHaveUndeleteAction = NO;
@ -14,6 +18,7 @@ void getUndeleteCommentData(id controller, id comment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[narwhalPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -32,7 +37,7 @@ void getUndeleteCommentData(id controller, id comment){
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; 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]; [controller performSelectorOnMainThread:@selector(completeUndeleteComment:) withObject:@{@"body":body, @"author":author, @"comment":comment} waitUntilDone:NO];
@ -107,6 +112,7 @@ void getUndeleteCommentData(id controller, id comment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[narwhalPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -125,7 +131,7 @@ void getUndeleteCommentData(id controller, id comment){
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; 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]; [self performSelectorOnMainThread:@selector(completeUndeletePost:) withObject:@{@"body":body, @"author":author, @"post":post} waitUntilDone:NO];
@ -142,7 +148,6 @@ void getUndeleteCommentData(id controller, id comment){
tfComment = [arg1 comment]; tfComment = [arg1 comment];
tfController = self; tfController = self;
shouldHaveUndeleteAction = YES; shouldHaveUndeleteAction = YES;
} }
} }
@ -159,7 +164,6 @@ void getUndeleteCommentData(id controller, id comment){
tfController = self; tfController = self;
tfComment = nil; tfComment = nil;
shouldHaveUndeleteAction = YES; shouldHaveUndeleteAction = YES;
} }
%orig; %orig;
@ -209,6 +213,10 @@ void getUndeleteCommentData(id controller, id comment){
%end %end
%ctor { %ctor {
narwhalPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[narwhalPrefs registerDouble:&narwhalRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
NSString* processName = [[NSProcessInfo processInfo] processName]; NSString* processName = [[NSProcessInfo processInfo] processName];
if ([processName isEqualToString:@"narwhal"]){ if ([processName isEqualToString:@"narwhal"]){

View File

@ -1,6 +1,12 @@
#import <Cephei/HBPreferences.h>
#import "Reddit.h" #import "Reddit.h"
HBPreferences *redditPrefs;
CGFloat redditRequestTimeoutValue;
NSArray *redditVersion;
%group Reddit_v4_current %group Reddit_v4_current
%hook CommentTreeNode %hook CommentTreeNode
@ -72,6 +78,7 @@
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -90,18 +97,16 @@
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
NSMutableAttributedString *bodyMutableAttributedText; NSMutableAttributedString *bodyMutableAttributedText;
id themeManager; id themeManager;
id isNightMode; id isNightMode;
id textColor; id textColor;
if ([appVersion[1] integerValue] >= 45){ if ([redditVersion[1] integerValue] >= 45){
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
@ -113,8 +118,7 @@
[themeManager release]; [themeManager release];
} else if ([redditVersion[1] integerValue] >= 37){
} else if ([appVersion[1] integerValue] >= 37){
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]]; themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
@ -219,6 +223,7 @@
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -237,16 +242,14 @@
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
id themeManager; id themeManager;
id isNightMode; id isNightMode;
id textColor; id textColor;
if ([appVersion[1] integerValue] >= 45){ if ([redditVersion[1] integerValue] >= 45){
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]]; themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
@ -258,7 +261,7 @@
[themeManager release]; [themeManager release];
} else if ([appVersion[1] integerValue] >= 37){ } else if ([redditVersion[1] integerValue] >= 37){
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]]; themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"]; isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
@ -295,9 +298,9 @@
[post setSelfPostRichTextAttributed:bodyMutableAttributedText]; [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
[post setPreviewFeedPostTextString:bodyMutableAttributedText]; [post setPreviewFeedPostTextString:bodyMutableAttributedText];
if ([appVersion[1] integerValue] >= 44){ if ([redditVersion[1] integerValue] >= 44){
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode]; [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
} else if ([appVersion[1] integerValue] >= 38) { } else if ([redditVersion[1] integerValue] >= 38) {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode]; [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
} else { } else {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode]; [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
@ -327,9 +330,8 @@
%new %new
-(void) updatePostText{ -(void) updatePostText{
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([appVersion[1] integerValue] >= 2){ if ([redditVersion[1] integerValue] >= 2){
[self reloadPostSection:YES]; [self reloadPostSection:YES];
} else { } else {
[self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO]; [self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
@ -351,9 +353,7 @@
id undeleteItem; id undeleteItem;
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."]; if ([redditVersion[1] integerValue] >= 18) {
if ([appVersion[1] integerValue] >= 18) {
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]]; undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
} else { } else {
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]]; undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
@ -379,6 +379,7 @@
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -397,7 +398,7 @@
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
@ -431,6 +432,7 @@
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -449,18 +451,16 @@
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:author]; [comment setAuthor:author];
[comment setBodyText:body]; [comment setBodyText:body];
[comment setBodyAttributedText:bodyMutableAttributedText]; [comment setBodyAttributedText:bodyMutableAttributedText];
if ([appVersion[1] integerValue] >= 12) { if ([redditVersion[1] integerValue] >= 12) {
[comment setBodyRichTextAttributed:bodyMutableAttributedText]; [comment setBodyRichTextAttributed:bodyMutableAttributedText];
} }
@ -492,9 +492,7 @@
id undeleteItem; id undeleteItem;
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."]; if ([redditVersion[1] integerValue] >= 18) {
if ([appVersion[1] integerValue] >= 18) {
undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]]; undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
} else { } else {
undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]]; undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
@ -525,6 +523,7 @@
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -543,7 +542,7 @@
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
@ -580,6 +579,7 @@
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]]; [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 setHTTPMethod:@"GET"];
[request setTimeoutInterval:[redditPrefs doubleForKey:@"requestTimeoutValue" default:10]];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@ -598,22 +598,20 @@
body = @"[pushshift has not archived this yet]"; body = @"[pushshift has not archived this yet]";
} }
} else if (error != nil || data == nil){ } else if (error != nil || data == nil){
body = @"[an error occured]"; body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]]; NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setAuthor:author]; [post setAuthor:author];
[post setSelfText:body]; [post setSelfText:body];
[post setSelfTextAttributed:bodyMutableAttributedText]; [post setSelfTextAttributed:bodyMutableAttributedText];
if ([appVersion[1] integerValue] >= 8) { if ([redditVersion[1] integerValue] >= 8) {
[post setSelfPostRichTextAttributed:bodyMutableAttributedText]; [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
} }
if ([appVersion[1] integerValue] >= 15) { if ([redditVersion[1] integerValue] >= 15) {
[post setPreviewFeedPostTextString:bodyMutableAttributedText]; [post setPreviewFeedPostTextString:bodyMutableAttributedText];
} }
@ -718,17 +716,20 @@
%ctor{ %ctor{
redditPrefs = [[HBPreferences alloc] initWithIdentifier:@"com.lint.undelete.prefs"];
[redditPrefs registerDouble:&redditRequestTimeoutValue default:10 forKey:@"requestTimeoutValue"];
NSString* processName = [[NSProcessInfo processInfo] processName]; NSString* processName = [[NSProcessInfo processInfo] processName];
NSArray* appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."]; redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
if ([processName isEqualToString:@"Reddit"]){ if ([processName isEqualToString:@"Reddit"]){
if ([appVersion[0] isEqualToString:@"4"]){ if ([redditVersion[0] isEqualToString:@"4"]){
if ([appVersion[1] integerValue] <= 32){ if ([redditVersion[1] integerValue] <= 32){
%init(Reddit_v4_ios10); %init(Reddit_v4_ios10);
} else{ } else{
%init(Reddit_v4_current); %init(Reddit_v4_current);
} }
} else if ([appVersion[0] isEqualToString:@"3"]) { } else if ([redditVersion[0] isEqualToString:@"3"]) {
%init(Reddit_v3); %init(Reddit_v3);
} }
} }