選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Reddit.xm 24KB

5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. }