diff --git a/tweak/Apollo.h b/tweak/Apollo.h index fa04951..910b811 100644 --- a/tweak/Apollo.h +++ b/tweak/Apollo.h @@ -26,6 +26,9 @@ @property(assign,nonatomic) NSString *author; @property(assign,nonatomic) NSString *fullName; -(BOOL) isSelfPost; + +//custom elements +@property(strong, nonatomic) NSString *undeleteAuthor; @end @interface CommentsHeaderCellNode @@ -68,10 +71,12 @@ @interface ASTextNode @property(assign,nonatomic) CGRect frame; -@property(assign,nonatomic) id attributedString; -@property(assign,nonatomic) id attributedText; +@property(assign,nonatomic) NSAttributedString *attributedString; +@property(assign,nonatomic) NSAttributedString *attributedText; @end @interface ApolloButtonNode -@property(assign,nonatomic) NSArray *subnodes; +@property(assign,nonatomic) ASTextNode *titleNode; +-(void) setAttributedTitle:(id) arg1 forState:(NSInteger) arg2; +-(id) attributedTitleForState:(NSInteger) arg1; @end diff --git a/tweak/Apollo.xm b/tweak/Apollo.xm index 55dd263..0458824 100644 --- a/tweak/Apollo.xm +++ b/tweak/Apollo.xm @@ -33,6 +33,21 @@ id apolloCommentController; %end +%hook RKLink +%property(strong, nonatomic) NSString *undeleteAuthor; + +-(id) author{ + + if ([self undeleteAuthor]){ + return [self undeleteAuthor]; + } else { + return %orig; + } +} + +%end + + %hook MarkdownRenderer +(id) attributedStringFromHTML:(id)arg1 attributes:(id) arg2 compact:(BOOL) arg3{ @@ -123,7 +138,7 @@ id apolloCommentController; -(void) moreOptionsTappedWithSender:(id) arg1{ - id commentBody = [MSHookIvar(self, "comment") body]; + NSString *commentBody = [MSHookIvar(self, "comment") body]; if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){ shouldAddUndeleteCell = YES; @@ -136,7 +151,7 @@ id apolloCommentController; -(void) longPressedWithGestureRecognizer:(id) arg1{ - id commentBody = [MSHookIvar(self, "comment") body]; + NSString *commentBody = [MSHookIvar(self, "comment") body]; if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){ shouldAddUndeleteCell = YES; @@ -150,7 +165,7 @@ id apolloCommentController; %new -(void) undeleteCellWasSelected{ - id comment = MSHookIvar(self, "comment"); + RKComment *comment = MSHookIvar(self, "comment"); [%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)]; } @@ -158,25 +173,22 @@ id apolloCommentController; %new -(void) completeUndeleteCommentAction:(NSDictionary *) data{ - id comment = MSHookIvar(self, "comment"); + RKComment *comment = MSHookIvar(self, "comment"); id bodyNode = MSHookIvar(self, "bodyNode"); id authorNode = MSHookIvar(self, "authorNode"); - id authorTextNode = [authorNode subnodes][0]; NSString *author = data[@"author"]; NSString *body = data[@"body"]; - id prevAuthorAttributedString = [authorTextNode attributedString]; + [comment setAuthor:author]; + [comment setBody:body]; + + NSAttributedString *prevAuthorAttributedString = [authorNode attributedTitleForState:UIControlStateNormal]; NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])]; NSAttributedString *newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes]; - [authorTextNode setAttributedText:newAuthorAttributedString]; - [authorTextNode setAttributedString:newAuthorAttributedString]; - + [authorNode setAttributedTitle:newAuthorAttributedString forState:UIControlStateNormal]; [bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]]; - - [comment setAuthor:author]; - [comment setBody:body]; } %end @@ -204,7 +216,7 @@ id apolloCommentController; %new -(void) undeleteCellWasSelected{ - id post = MSHookIvar(self, "link"); + RKLink *post = MSHookIvar(self, "link"); [%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; } @@ -212,28 +224,26 @@ id apolloCommentController; %new -(void) completeUndeletePostAction:(NSDictionary *) data{ + RKLink *post = MSHookIvar(self, "link"); + id headerCellNode = [self headerCellNode]; id bodyNode = MSHookIvar(headerCellNode, "bodyNode"); id postInfoNode = MSHookIvar(headerCellNode, "postInfoNode"); id authorNode = MSHookIvar(postInfoNode, "authorButtonNode"); - id authorTextNode = [authorNode subnodes][0]; NSString *author = data[@"author"]; NSString *authorTextString = [NSString stringWithFormat:@"by %@", author]; NSString *body = data[@"body"]; - id post = MSHookIvar(self, "link"); - //MSHookIvar(post, "_author") = author; //Crashes when clicking on author name. You will have to search the author name to go find the profile. - - id prevAuthorAttributedString = [authorTextNode attributedString]; + [post setUndeleteAuthor:author]; + [post setSelfText:body]; + + NSAttributedString *prevAuthorAttributedString = [authorNode attributedTitleForState:UIControlStateNormal]; NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])]; NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:authorTextString attributes:authorStringAttributes]; - [authorTextNode setAttributedText:newAuthorAttributedString]; - [authorTextNode setAttributedString:newAuthorAttributedString]; - + [authorNode setAttributedTitle:newAuthorAttributedString forState:UIControlStateNormal]; [bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]]; - [post setSelfText:body]; } %end