Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #import "Narwhal.h"
  2. %group Narwhal
  3. BOOL shouldHaveUndeleteAction = NO;
  4. id tfComment;
  5. id tfController;
  6. void getUndeleteCommentData(id controller, id comment){
  7. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  8. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  9. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]];
  10. [request setHTTPMethod:@"GET"];
  11. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  12. NSString *author = @"[author]";
  13. NSString *body = @"[body]";
  14. if (data != nil && error == nil){
  15. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  16. if ([[jsonData objectForKey:@"data"] count] != 0){
  17. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  18. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  19. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  20. body = @"[pushshift was unable to archive this]";
  21. }
  22. } else {
  23. body = @"[pushshift has not archived this yet]";
  24. }
  25. } else if (error != nil || data == nil){
  26. body = @"[an error occured]";
  27. }
  28. [controller performSelectorOnMainThread:@selector(completeUndeleteComment:) withObject:@{@"body":body, @"author":author, @"comment":comment} waitUntilDone:NO];
  29. }];
  30. }
  31. %hook UIViewController
  32. -(void) presentViewController:(id) arg1 animated:(BOOL) arg2 completion:(id) arg3{
  33. if ([arg1 isKindOfClass:[UIAlertController class]] && shouldHaveUndeleteAction){
  34. UIAlertAction* undeleteAction;
  35. if (tfComment){
  36. undeleteAction = [UIAlertAction actionWithTitle:@"tf did that say?" style:nil handler:^(UIAlertAction* action){getUndeleteCommentData(tfController, tfComment);}];
  37. } else {
  38. undeleteAction = [UIAlertAction actionWithTitle:@"tf did that say?" style:nil handler:^(UIAlertAction* action){[tfController handleUndeletePostAction];}];
  39. }
  40. [arg1 addAction:undeleteAction];
  41. }
  42. %orig;
  43. }
  44. %end
  45. %hook NRTLinkViewController
  46. %new
  47. -(void) completeUndeleteComment:(id) data{
  48. id comment = data[@"comment"];
  49. if (comment){
  50. MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
  51. MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
  52. [[self commentsManager] updateComment:comment fromEdited:comment];
  53. }
  54. }
  55. %new
  56. -(void) completeUndeletePost:(id) data{
  57. id post = data[@"post"];
  58. MSHookIvar<NSString*>(post, "_author") = data[@"author"];
  59. NSAttributedString* postBodyAttributedString = [%c(NRTMarkdownManager) attributedStringFromMarkdown:data[@"body"] type:0];
  60. [self setLinkText:postBodyAttributedString];
  61. [[self tableView] reloadData];
  62. }
  63. %new
  64. -(void) handleUndeletePostAction{
  65. id post = [self link];
  66. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  67. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  68. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]];
  69. [request setHTTPMethod:@"GET"];
  70. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  71. NSString *author = @"[author]";
  72. NSString *body = @"[body]";
  73. if (data != nil && error == nil){
  74. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  75. if ([[jsonData objectForKey:@"data"] count] != 0){
  76. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  77. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  78. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  79. body = @"[pushshift was unable to archive this]";
  80. }
  81. } else {
  82. body = @"[pushshift has not archived this yet]";
  83. }
  84. } else if (error != nil || data == nil){
  85. body = @"[an error occured]";
  86. }
  87. [self performSelectorOnMainThread:@selector(completeUndeletePost:) withObject:@{@"body":body, @"author":author, @"post":post} waitUntilDone:NO];
  88. }];
  89. }
  90. -(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
  91. if (arg2 == 2){
  92. if ([arg1 isKindOfClass:[%c(NRTCommentTableViewCell) class]]) {
  93. tfComment = [arg1 comment];
  94. tfController = self;
  95. shouldHaveUndeleteAction = YES;
  96. }
  97. }
  98. %orig;
  99. shouldHaveUndeleteAction = NO;
  100. }
  101. -(void) _dotsButtonTouched:(id) arg1{
  102. if ([self linkTextOffscreenCell]){
  103. tfController = self;
  104. tfComment = nil;
  105. shouldHaveUndeleteAction = YES;
  106. }
  107. %orig;
  108. shouldHaveUndeleteAction = NO;
  109. }
  110. %end
  111. %hook NRTMediaTableViewDataSource
  112. %new
  113. -(void) completeUndeleteComment:(id) data{
  114. id comment = data[@"comment"];
  115. if (comment){
  116. MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
  117. MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
  118. [[self commentsManager] updateComment:comment fromEdited:comment];
  119. }
  120. }
  121. -(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
  122. if (arg2 == 2){
  123. if ([arg1 isKindOfClass:[%c(NRTCommentTableViewCell) class]]) {
  124. tfComment = [arg1 comment];
  125. tfController = self;
  126. shouldHaveUndeleteAction = YES;
  127. }
  128. }
  129. %orig;
  130. shouldHaveUndeleteAction = NO;
  131. }
  132. %end
  133. %end
  134. %ctor {
  135. NSString* processName = [[NSProcessInfo processInfo] processName];
  136. if ([processName isEqualToString:@"narwhal"]){
  137. %init(Narwhal);
  138. }
  139. }