Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 5 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #import "AlienBlue.h"
  2. #import "assets/TFHelper.h"
  3. #import "assets/MMMarkdown/MMMarkdown.h"
  4. static BOOL isAlienBlueEnabled;
  5. static BOOL isTFDeletedOnly;
  6. static CGFloat pushshiftRequestTimeoutValue;
  7. %group AlienBlue
  8. %hook CommentOptionsDrawerView
  9. -(id) initWithNode:(id) arg1 {
  10. id orig = %orig;
  11. NSString *body;
  12. if ([self isPostHeader]) {
  13. body = [[arg1 post] selftext];
  14. } else {
  15. body = [[(CommentNode *)arg1 comment] body];
  16. }
  17. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:body isDeletedOnly:isTFDeletedOnly]){
  18. CGSize refSize = [[self buttons][0] frame].size;
  19. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  20. [undeleteButton setFrame:CGRectMake(0, 0, refSize.width, refSize.height)];
  21. if ([self isPostHeader]){
  22. [undeleteButton addTarget:self action:@selector(didTapPostUndeleteButton:) forControlEvents:UIControlEventTouchUpInside];
  23. } else {
  24. [undeleteButton addTarget:self action:@selector(didTapCommentUndeleteButton:) forControlEvents:UIControlEventTouchUpInside];
  25. }
  26. if ([%c(Resources) isNight]) {
  27. [undeleteButton setImage:[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"] forState:UIControlStateNormal];
  28. } else {
  29. [undeleteButton setImage:[UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160light.png"] forState:UIControlStateNormal];
  30. }
  31. undeleteButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
  32. undeleteButton.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
  33. [self addButton:undeleteButton];
  34. }
  35. return orig;
  36. }
  37. %new
  38. -(void) didTapCommentUndeleteButton:(id) sender {
  39. [sender setEnabled:NO];
  40. id comment = [[self node] comment];
  41. [%c(TFHelper) getUndeleteDataWithID:[comment ident] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  42. }
  43. %new
  44. -(void) completeUndeleteCommentAction:(NSDictionary *) data{
  45. id comment = [[self node] comment];
  46. NSString *body = data[@"body"];
  47. NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
  48. [comment setAuthor:data[@"author"]];
  49. [comment setBody:body];
  50. [comment setBodyHTML:bodyHTML];
  51. [[self delegate] respondToStyleChange];
  52. [data[@"sender"] setEnabled:YES];
  53. }
  54. %new
  55. -(void) didTapPostUndeleteButton:(id) sender {
  56. [sender setEnabled:NO];
  57. id post = [[self node] post];
  58. [%c(TFHelper) getUndeleteDataWithID:[post ident] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  59. }
  60. %new
  61. -(void) completeUndeletePostAction:(NSDictionary *) data{
  62. id post = [[self node] post];
  63. id postComment = [[self node] comment]; //Don't know why he used a comment to store info about a post, but it exists
  64. NSString *body = data[@"body"];
  65. NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
  66. [post setAuthor:data[@"author"]];
  67. [post setSelftext:body];
  68. [postComment setBodyHTML:bodyHTML];
  69. [[self delegate] respondToStyleChange];
  70. [data[@"sender"] setEnabled:YES];
  71. }
  72. %end
  73. %end
  74. static void loadPrefs(){
  75. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
  76. if (prefs){
  77. if ([prefs objectForKey:@"isAlienBlueEnabled"] != nil){
  78. isAlienBlueEnabled = [[prefs objectForKey:@"isAlienBlueEnabled"] boolValue];
  79. } else {
  80. isAlienBlueEnabled = YES;
  81. }
  82. if ([prefs objectForKey:@"isTFDeletedOnly"] != nil){
  83. isTFDeletedOnly = [[prefs objectForKey:@"isTFDeletedOnly"] boolValue];
  84. } else {
  85. isTFDeletedOnly = YES;
  86. }
  87. if ([prefs objectForKey:@"requestTimeoutValue"] != nil){
  88. pushshiftRequestTimeoutValue = [[prefs objectForKey:@"requestTimeoutValue"] doubleValue];
  89. } else {
  90. pushshiftRequestTimeoutValue = 10;
  91. }
  92. } else {
  93. isAlienBlueEnabled = YES;
  94. isTFDeletedOnly = YES;
  95. pushshiftRequestTimeoutValue = 10;
  96. }
  97. }
  98. static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  99. loadPrefs();
  100. }
  101. %ctor {
  102. loadPrefs();
  103. NSString* processName = [[NSProcessInfo processInfo] processName];
  104. if ([processName isEqualToString:@"AlienBlue"]){
  105. if (isAlienBlueEnabled){
  106. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
  107. %init(AlienBlue);
  108. }
  109. }
  110. }