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 26KB

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