You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Reddit.xm 27KB

5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
5 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. #import "Reddit.h"
  2. static CGFloat pushshiftRequestTimeoutValue;
  3. static BOOL isRedditEnabled;
  4. NSArray *redditVersion;
  5. %group Reddit_v4_current
  6. %hook CommentTreeNode
  7. %property(assign,nonatomic)id commentTreeHeaderNode;
  8. %property(assign,nonatomic)id commentTreeCommandBarNode;
  9. %end
  10. %hook CommentTreeHeaderView
  11. -(void) layoutSubviews{
  12. %orig;
  13. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  14. }
  15. %end
  16. %hook CommentTreeHeaderNode
  17. -(void) didLoad{
  18. %orig;
  19. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  20. }
  21. %end
  22. %hook CommentTreeCommandBarNode
  23. -(void) didLoad{
  24. %orig;
  25. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  26. }
  27. %end
  28. %hook CommentActionSheetViewController
  29. -(void) setItems:(id) arg1{
  30. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  31. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  32. CGFloat scale = origImage.size.width / existingImageSize.width;
  33. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  34. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  35. %orig([arg1 arrayByAddingObject:undeleteItem]);
  36. [undeleteItem release];
  37. }
  38. -(void) handleDidSelectActionSheetItem:(id) arg1{
  39. %orig;
  40. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  41. [self dismissViewControllerAnimated:YES completion:nil];
  42. id commentTreeNode = [self commentTreeNode];
  43. Comment *comment = [commentTreeNode comment];
  44. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  45. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  46. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
  47. [request setHTTPMethod:@"GET"];
  48. [request setTimeoutInterval:pushshiftRequestTimeoutValue];
  49. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  50. NSString *author = @"[author]";
  51. NSString *body = @"[body]";
  52. if (data != nil && error == nil){
  53. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  54. if ([[jsonData objectForKey:@"data"] count] != 0){
  55. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  56. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  57. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  58. body = @"[pushshift was unable to archive this]";
  59. }
  60. } else {
  61. body = @"[pushshift has not archived this yet]";
  62. }
  63. } else if (error != nil || data == nil){
  64. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  65. }
  66. NSMutableAttributedString *bodyMutableAttributedText;
  67. id themeManager;
  68. id isNightMode;
  69. id textColor;
  70. if ([redditVersion[1] integerValue] >= 45){
  71. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  72. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  73. if (isNightMode) {
  74. textColor = [[themeManager darkTheme] bodyTextColor];
  75. } else{
  76. textColor = [[themeManager lightTheme] bodyTextColor];
  77. }
  78. [themeManager release];
  79. } else if ([redditVersion[1] integerValue] >= 37){
  80. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  81. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  82. if (isNightMode) {
  83. textColor = [[themeManager nightTheme] bodyTextColor];
  84. } else{
  85. textColor = [[themeManager dayTheme] bodyTextColor];
  86. }
  87. [themeManager release];
  88. } else {
  89. themeManager = [%c(ThemeManager) sharedManager];
  90. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  91. if (isNightMode) {
  92. textColor = [[themeManager nightTheme] bodyTextColor];
  93. } else{
  94. textColor = [[themeManager dayTheme] bodyTextColor];
  95. }
  96. }
  97. bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  98. [bodyMutableAttributedText beginEditing];
  99. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  100. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  101. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  102. }];
  103. [bodyMutableAttributedText endEditing];
  104. [comment setAuthor:author];
  105. [comment setBodyText:body];
  106. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  107. [comment setBodyAttributedText:bodyMutableAttributedText];
  108. [[commentTreeNode commentTreeHeaderNode] performSelectorOnMainThread:@selector(updateContentViewsForData:) withObject:comment waitUntilDone:NO];
  109. [request release];
  110. [queue release];
  111. [bodyMutableAttributedText release];
  112. }];
  113. }
  114. }
  115. %end
  116. %hook PostDetailViewController
  117. %property(strong,nonatomic) id feedPostTextWithThumbnailNode;
  118. %property(strong,nonatomic) id feedPostDetailCellNode;
  119. %end
  120. %hook FeedPostDetailCellNode
  121. -(void) didLoad{
  122. %orig;
  123. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  124. }
  125. %end
  126. %hook PostActionSheetViewController
  127. -(void) setItems:(id) arg1{
  128. Post *post = [self post];
  129. if ([post isSelfPost]){
  130. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  131. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  132. CGFloat scale = origImage.size.width / existingImageSize.width;
  133. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  134. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  135. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  136. [undeleteItem release];
  137. }
  138. %orig;
  139. }
  140. -(void) handleDidSelectActionSheetItem:(id) arg1{
  141. %orig;
  142. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  143. [self dismissViewControllerAnimated:YES completion:nil];
  144. Post *post = [self post];
  145. if ([post isSelfPost]){
  146. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  147. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  148. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  149. [request setHTTPMethod:@"GET"];
  150. [request setTimeoutInterval:pushshiftRequestTimeoutValue];
  151. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  152. NSString *author = @"[author]";
  153. NSString *body = @"[body]";
  154. if (data != nil && error == nil){
  155. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  156. if ([[jsonData objectForKey:@"data"] count] != 0){
  157. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  158. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  159. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  160. body = @"[pushshift was unable to archive this]";
  161. }
  162. } else {
  163. body = @"[pushshift has not archived this yet]";
  164. }
  165. } else if (error != nil || data == nil){
  166. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  167. }
  168. id themeManager;
  169. id isNightMode;
  170. id textColor;
  171. if ([redditVersion[1] integerValue] >= 45){
  172. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  173. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  174. if (isNightMode) {
  175. textColor = [[themeManager darkTheme] bodyTextColor];
  176. } else{
  177. textColor = [[themeManager lightTheme] bodyTextColor];
  178. }
  179. [themeManager release];
  180. } else if ([redditVersion[1] integerValue] >= 37){
  181. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  182. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  183. if (isNightMode) {
  184. textColor = [[themeManager nightTheme] bodyTextColor];
  185. } else{
  186. textColor = [[themeManager dayTheme] bodyTextColor];
  187. }
  188. [themeManager release];
  189. } else {
  190. themeManager = [%c(ThemeManager) sharedManager];
  191. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  192. if (isNightMode) {
  193. textColor = [[themeManager nightTheme] bodyTextColor];
  194. } else{
  195. textColor = [[themeManager dayTheme] bodyTextColor];
  196. }
  197. }
  198. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  199. [bodyMutableAttributedText beginEditing];
  200. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  201. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  202. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  203. }];
  204. [bodyMutableAttributedText endEditing];
  205. [post setSelfText:body];
  206. [post setAuthor:author];
  207. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  208. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  209. if ([redditVersion[1] integerValue] >= 44){
  210. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  211. } else if ([redditVersion[1] integerValue] >= 38) {
  212. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  213. } else {
  214. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  215. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
  216. }
  217. [request release];
  218. [queue release];
  219. [bodyMutableAttributedText release];
  220. }];
  221. }
  222. }
  223. }
  224. %end
  225. %end
  226. %group Reddit_v4_ios10
  227. %hook CommentsViewController
  228. %new
  229. -(void) updateComments{
  230. [self reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  231. }
  232. %new
  233. -(void) updatePostText{
  234. if ([redditVersion[1] integerValue] >= 2){
  235. [self reloadPostSection:YES];
  236. } else {
  237. [self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
  238. }
  239. }
  240. %end
  241. %hook CommentActionSheetViewController
  242. -(void) setItems:(id) arg1{
  243. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  244. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  245. CGFloat scale = origImage.size.width / existingImageSize.width;
  246. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  247. id undeleteItem;
  248. if ([redditVersion[1] integerValue] >= 18) {
  249. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  250. } else {
  251. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  252. }
  253. %orig([arg1 arrayByAddingObject:undeleteItem]);
  254. [undeleteItem release];
  255. }
  256. // >= 4.21
  257. -(void) handleDidSelectActionSheetItem:(id) arg1{
  258. %orig;
  259. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  260. [self dismissViewControllerAnimated:YES completion:nil];
  261. Comment *comment = [self comment];
  262. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  263. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  264. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
  265. [request setHTTPMethod:@"GET"];
  266. [request setTimeoutInterval:pushshiftRequestTimeoutValue];
  267. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  268. NSString *author = @"[author]";
  269. NSString *body = @"[body]";
  270. if (data != nil && error == nil){
  271. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  272. if ([[jsonData objectForKey:@"data"] count] != 0){
  273. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  274. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  275. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  276. body = @"[pushshift was unable to archive this]";
  277. }
  278. } else {
  279. body = @"[pushshift has not archived this yet]";
  280. }
  281. } else if (error != nil || data == nil){
  282. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  283. }
  284. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  285. [comment setAuthor:author];
  286. [comment setBodyText:body];
  287. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  288. [comment setBodyAttributedText:bodyMutableAttributedText];
  289. [[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
  290. [request release];
  291. [queue release];
  292. [bodyMutableAttributedText release];
  293. }];
  294. }
  295. }
  296. // <= 4.20
  297. -(void) actionSheetViewController:(id) arg1 didSelectItem:(id) arg2{
  298. %orig;
  299. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  300. [self dismissViewControllerAnimated:YES completion:nil];
  301. Comment *comment = [self comment];
  302. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  303. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  304. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
  305. [request setHTTPMethod:@"GET"];
  306. [request setTimeoutInterval:pushshiftRequestTimeoutValue];
  307. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  308. NSString *author = @"[author]";
  309. NSString *body = @"[body]";
  310. if (data != nil && error == nil){
  311. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  312. if ([[jsonData objectForKey:@"data"] count] != 0){
  313. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  314. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  315. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  316. body = @"[pushshift was unable to archive this]";
  317. }
  318. } else {
  319. body = @"[pushshift has not archived this yet]";
  320. }
  321. } else if (error != nil || data == nil){
  322. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  323. }
  324. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  325. [comment setAuthor:author];
  326. [comment setBodyText:body];
  327. [comment setBodyAttributedText:bodyMutableAttributedText];
  328. if ([redditVersion[1] integerValue] >= 12) {
  329. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  330. }
  331. [[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
  332. [request release];
  333. [queue release];
  334. [bodyMutableAttributedText release];
  335. }];
  336. }
  337. }
  338. %end
  339. %hook PostActionSheetViewController
  340. -(void) setItems:(id) arg1{
  341. Post *post = [self post];
  342. if ([post isSelfPost]){
  343. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  344. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  345. CGFloat scale = origImage.size.width / existingImageSize.width;
  346. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  347. id undeleteItem;
  348. if ([redditVersion[1] integerValue] >= 18) {
  349. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  350. } else {
  351. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  352. }
  353. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  354. [undeleteItem release];
  355. }
  356. %orig;
  357. }
  358. // >= 4.21
  359. -(void) handleDidSelectActionSheetItem:(id) arg1{
  360. %orig;
  361. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  362. [self dismissViewControllerAnimated:YES completion:nil];
  363. Post *post = [self post];
  364. if ([post isSelfPost]){
  365. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  366. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  367. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  368. [request setHTTPMethod:@"GET"];
  369. [request setTimeoutInterval:pushshiftRequestTimeoutValue];
  370. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  371. NSString *author = @"[author]";
  372. NSString *body = @"[body]";
  373. if (data != nil && error == nil){
  374. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  375. if ([[jsonData objectForKey:@"data"] count] != 0){
  376. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  377. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  378. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  379. body = @"[pushshift was unable to archive this]";
  380. }
  381. } else {
  382. body = @"[pushshift has not archived this yet]";
  383. }
  384. } else if (error != nil || data == nil){
  385. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  386. }
  387. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  388. [post setSelfText:body];
  389. [post setAuthor:author];
  390. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  391. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  392. [[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
  393. [request release];
  394. [queue release];
  395. [bodyMutableAttributedText release];
  396. }];
  397. }
  398. }
  399. }
  400. // <= 4.20
  401. -(void) actionSheetViewController:(id) arg1 didSelectItem:(id) arg2{
  402. %orig;
  403. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  404. [self dismissViewControllerAnimated:YES completion:nil];
  405. Post *post = [self post];
  406. if ([post isSelfPost]){
  407. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  408. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  409. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  410. [request setHTTPMethod:@"GET"];
  411. [request setTimeoutInterval:pushshiftRequestTimeoutValue];
  412. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  413. NSString *author = @"[author]";
  414. NSString *body = @"[body]";
  415. if (data != nil && error == nil){
  416. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  417. if ([[jsonData objectForKey:@"data"] count] != 0){
  418. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  419. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  420. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  421. body = @"[pushshift was unable to archive this]";
  422. }
  423. } else {
  424. body = @"[pushshift has not archived this yet]";
  425. }
  426. } else if (error != nil || data == nil){
  427. body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
  428. }
  429. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  430. [post setAuthor:author];
  431. [post setSelfText:body];
  432. [post setSelfTextAttributed:bodyMutableAttributedText];
  433. if ([redditVersion[1] integerValue] >= 8) {
  434. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  435. }
  436. if ([redditVersion[1] integerValue] >= 15) {
  437. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  438. }
  439. [[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
  440. [request release];
  441. [queue release];
  442. [bodyMutableAttributedText release];
  443. }];
  444. }
  445. }
  446. }
  447. %end
  448. %end
  449. //outdated and unchanged from first version of this tweak...
  450. //TODO: move button to menu, add post support, make async requests once I feel like doing it
  451. %group Reddit_v3
  452. %hook CommentView
  453. %new
  454. -(void) buttonAction {
  455. id commentsViewController = [self delegate];
  456. id comment = [self comment];
  457. NSError* error;
  458. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  459. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment pkWithoutPrefix]]]];
  460. [request setHTTPMethod:@"GET"];
  461. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
  462. NSString *author = @"[author]";
  463. NSString *body = @"[body]";
  464. if (data != nil && error == nil){
  465. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  466. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  467. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  468. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  469. body = @"[comment was unable to be archived]";
  470. }
  471. } else if (error != nil || data == nil){
  472. body = @"[an error occured]";
  473. }
  474. [comment setValue:author forKey:@"author"];
  475. [comment setValue:[%c(MarkDownParser) attributedStringFromMarkdownString: body] forKey:@"bodyAttributedText"];
  476. [comment setValue:body forKey:@"bodyText"];
  477. [commentsViewController reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  478. }
  479. -(id) initWithFrame:(id)arg1{
  480. id orig = %orig;
  481. id commandView = [self commandView];
  482. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  483. [undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
  484. UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  485. [undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
  486. [commandView setUndeleteButton:undeleteButton];
  487. [commandView addSubview:undeleteButton];
  488. return orig;
  489. }
  490. %end
  491. %hook CommentCommandView
  492. %property (assign, nonatomic) id undeleteButton;
  493. -(void) layoutSubviews{
  494. %orig;
  495. UIButton *button = [self undeleteButton];
  496. button.frame = CGRectMake([[self overflowButton ] frame].origin.x - 32, 0, 32, 32);
  497. }
  498. %end
  499. %end
  500. static void loadPrefs(){
  501. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
  502. if (prefs){
  503. if ([prefs objectForKey:@"isRedditEnabled"] != nil){
  504. isRedditEnabled = [[prefs objectForKey:@"isRedditEnabled"] boolValue];
  505. } else {
  506. isRedditEnabled = YES;
  507. }
  508. if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
  509. pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
  510. } else {
  511. pushshiftRequestTimeoutValue = 10;
  512. }
  513. } else {
  514. isRedditEnabled = YES;
  515. pushshiftRequestTimeoutValue = 10;
  516. }
  517. }
  518. %ctor{
  519. loadPrefs();
  520. NSString* processName = [[NSProcessInfo processInfo] processName];
  521. redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
  522. if ([processName isEqualToString:@"Reddit"]){
  523. if (isRedditEnabled) {
  524. if ([redditVersion[0] isEqualToString:@"4"]){
  525. if ([redditVersion[1] integerValue] <= 32){
  526. %init(Reddit_v4_ios10);
  527. } else{
  528. %init(Reddit_v4_current);
  529. }
  530. } else if ([redditVersion[0] isEqualToString:@"3"]) {
  531. %init(Reddit_v3);
  532. }
  533. }
  534. }
  535. }