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.

765 lines
24KB

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