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.

316 lines
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] setFeedPostTextWithThumbnailNode:[self textNode]];
  123. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  124. }
  125. %end
  126. %hook PostActionSheetViewController
  127. -(void) setItems:(id) arg1{
  128. id post = [self post];
  129. if ([post isSelfPost]){
  130. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  131. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  132. CGFloat scale = origImage.size.width / existingImageSize.width;
  133. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  134. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  135. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  136. [undeleteItem release];
  137. }
  138. %orig;
  139. }
  140. -(void) handleDidSelectActionSheetItem:(id) arg1{
  141. %orig;
  142. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  143. [self dismissViewControllerAnimated:YES completion:nil];
  144. id post = [self post];
  145. if ([post isSelfPost]){
  146. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  147. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  148. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  149. [request setHTTPMethod:@"GET"];
  150. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  151. NSString *author = @"[author]";
  152. NSString *body = @"[body]";
  153. if (data != nil && error == nil){
  154. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  155. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  156. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  157. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  158. body = @"[comment was unable to be archived]";
  159. }
  160. } else if (error != nil || data == nil){
  161. body = @"[an error occured]";
  162. }
  163. id themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  164. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  165. id textColor;
  166. if (isNightMode) {
  167. textColor = [[themeManager nightTheme] bodyTextColor];
  168. } else{
  169. textColor = [[themeManager dayTheme] bodyTextColor];
  170. }
  171. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  172. [bodyMutableAttributedText beginEditing];
  173. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  174. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  175. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  176. }];
  177. [bodyMutableAttributedText endEditing];
  178. [post setValue:bodyMutableAttributedText forKey:@"selfPostRichTextAttributed"];
  179. [post setValue:bodyMutableAttributedText forKey:@"previewFeedPostTextString"];
  180. [post setAuthor:author];
  181. [post setValue:body forKey:@"selfText"];
  182. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  183. [request release];
  184. [queue release];
  185. [bodyMutableAttributedText release];
  186. [themeManager release];
  187. }];
  188. }
  189. }
  190. }
  191. %end
  192. %end
  193. %ctor{
  194. NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  195. NSArray* versionArray = [version componentsSeparatedByString:@"."];
  196. if ([versionArray[0] isEqualToString:@"4"]){
  197. %init(Redditv4);
  198. } else if ([versionArray[0] isEqualToString:@"3"]) {
  199. }
  200. }