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.

315 line
10KB

  1. #include "Tweak.h"
  2. %group Redditv4
  3. %hook CommentTreeNode
  4. %property(assign,nonatomic)id commentTreeHeaderNode;
  5. %property(assign,nonatomic)id commentTreeCommandBarNode;
  6. %property(assign,nonatomic)BOOL isLoadingArchivedComment;
  7. %end
  8. %hook CommentTreeHeaderNode
  9. -(void) didLoad{
  10. %orig;
  11. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  12. }
  13. %end
  14. %hook CommentTreeCommandBarNode
  15. %property(assign,nonatomic) id activityIndicator;
  16. %property(assign,nonatomic) id undeleteButton;
  17. -(void) didLoad{
  18. %orig;
  19. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  20. [[self commentTreeNode] setIsLoadingArchivedComment:NO];
  21. }
  22. %end
  23. /*
  24. %hook ASCollectionView
  25. -(id) dequeueReusableCellWithReuseIdentifier: (id) arg1 forIndexPath:(id) arg2{
  26. id orig = %orig;
  27. if ([orig isKindOfClass:[%c(_ASCollectionViewCell) class]]){
  28. id node = [[orig node] contentNode];
  29. if ([node isKindOfClass:[%c(CommentTreeDisplayNode) class]]) {
  30. id commentNode = [node commentNode];
  31. if ([commentNode isLoadingArchivedComment]){
  32. //[[[commentNode commentTreeCommandBarNode] activityIndicator] startAnimating];
  33. }
  34. }
  35. }
  36. return orig;
  37. }
  38. %end
  39. */
  40. %hook CommentActionSheetViewController
  41. -(void) setItems:(id) arg1{
  42. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  43. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  44. CGFloat scale = origImage.size.width / existingImageSize.width;
  45. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  46. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  47. %orig([arg1 arrayByAddingObject:undeleteItem]);
  48. [undeleteItem release];
  49. }
  50. -(void) handleDidSelectActionSheetItem:(id) arg1{
  51. %orig;
  52. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  53. [self dismissViewControllerAnimated:YES completion:nil];
  54. id commentTreeNode = [self commentTreeNode];
  55. id comment = [commentTreeNode comment];
  56. [commentTreeNode setIsLoadingArchivedComment:YES];
  57. /*
  58. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  59. if (isNightMode){
  60. UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  61. } else {
  62. UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  63. }
  64. [self setActivityIndicator:activityIndicator];
  65. [activityIndicator startAnimating];
  66. [sender addSubview:activityIndicator];
  67. */
  68. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  69. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  70. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
  71. [request setHTTPMethod:@"GET"];
  72. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  73. NSString *author = @"[author]";
  74. NSString *body = @"[body]";
  75. if (data != nil && error == nil){
  76. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  77. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  78. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  79. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  80. body = @"[comment was unable to be archived]";
  81. }
  82. } else if (error != nil || data == nil){
  83. body = @"[an error occured]";
  84. }
  85. id themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  86. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  87. id textColor;
  88. if (isNightMode) {
  89. textColor = [[themeManager nightTheme] bodyTextColor];
  90. } else{
  91. textColor = [[themeManager dayTheme] bodyTextColor];
  92. }
  93. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  94. [bodyMutableAttributedText beginEditing];
  95. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  96. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  97. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  98. }];
  99. [bodyMutableAttributedText endEditing];
  100. [comment setValue:bodyMutableAttributedText forKey:@"bodyRichTextAttributed"];
  101. [comment setValue:author forKey:@"author"];
  102. [comment setValue:body forKey:@"bodyText"];
  103. [comment setValue:bodyMutableAttributedText forKey:@"bodyAttributedText"];
  104. [[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
  105. [commentTreeNode setIsLoadingArchivedComment:NO];
  106. //[activityIndicator stopAnimating];
  107. [request release];
  108. [queue release];
  109. [bodyMutableAttributedText release];
  110. [themeManager release];
  111. }];
  112. }
  113. }
  114. %end
  115. %hook PostDetailViewController
  116. %property(assign,nonatomic) id feedPostTextWithThumbnailNode;
  117. %property(assign,nonatomic) id feedPostDetailCellNode;
  118. %end
  119. %hook FeedPostDetailCellNode
  120. -(void) didLoad{
  121. %orig;
  122. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  123. }
  124. %end
  125. %hook PostActionSheetViewController
  126. -(void) setItems:(id) arg1{
  127. id post = [self post];
  128. if ([post isSelfPost]){
  129. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  130. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  131. CGFloat scale = origImage.size.width / existingImageSize.width;
  132. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  133. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  134. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  135. [undeleteItem release];
  136. }
  137. %orig;
  138. }
  139. -(void) handleDidSelectActionSheetItem:(id) arg1{
  140. %orig;
  141. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  142. [self dismissViewControllerAnimated:YES completion:nil];
  143. id post = [self post];
  144. if ([post isSelfPost]){
  145. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  146. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  147. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  148. [request setHTTPMethod:@"GET"];
  149. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  150. NSString *author = @"[author]";
  151. NSString *body = @"[body]";
  152. if (data != nil && error == nil){
  153. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  154. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  155. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  156. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  157. body = @"[comment was unable to be archived]";
  158. }
  159. } else if (error != nil || data == nil){
  160. body = @"[an error occured]";
  161. }
  162. id themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  163. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  164. id textColor;
  165. if (isNightMode) {
  166. textColor = [[themeManager nightTheme] bodyTextColor];
  167. } else{
  168. textColor = [[themeManager dayTheme] bodyTextColor];
  169. }
  170. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  171. [bodyMutableAttributedText beginEditing];
  172. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  173. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  174. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  175. }];
  176. [bodyMutableAttributedText endEditing];
  177. [post setValue:bodyMutableAttributedText forKey:@"selfPostRichTextAttributed"];
  178. [post setValue:bodyMutableAttributedText forKey:@"previewFeedPostTextString"];
  179. [post setAuthor:author];
  180. [post setValue:body forKey:@"selfText"];
  181. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  182. [request release];
  183. [queue release];
  184. [bodyMutableAttributedText release];
  185. [themeManager release];
  186. }];
  187. }
  188. }
  189. }
  190. %end
  191. %end
  192. %ctor{
  193. NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  194. NSArray* versionArray = [version componentsSeparatedByString:@"."];
  195. if ([versionArray[0] isEqualToString:@"4"]){
  196. %init(Redditv4);
  197. } else if ([versionArray[0] isEqualToString:@"3"]) {
  198. }
  199. }