Browse Source

Fix Apollo author labels

master
lint 4 years ago
parent
commit
369e3becf2
2 changed files with 40 additions and 25 deletions
  1. +8
    -3
      tweak/Apollo.h
  2. +32
    -22
      tweak/Apollo.xm

+ 8
- 3
tweak/Apollo.h View File

@property(assign,nonatomic) NSString *author; @property(assign,nonatomic) NSString *author;
@property(assign,nonatomic) NSString *fullName; @property(assign,nonatomic) NSString *fullName;
-(BOOL) isSelfPost; -(BOOL) isSelfPost;
//custom elements
@property(strong, nonatomic) NSString *undeleteAuthor;
@end @end
@interface CommentsHeaderCellNode @interface CommentsHeaderCellNode
@interface ASTextNode @interface ASTextNode
@property(assign,nonatomic) CGRect frame; @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 @end
@interface ApolloButtonNode @interface ApolloButtonNode
@property(assign,nonatomic) NSArray *subnodes;
@property(assign,nonatomic) ASTextNode *titleNode;
-(void) setAttributedTitle:(id) arg1 forState:(NSInteger) arg2;
-(id) attributedTitleForState:(NSInteger) arg1;
@end @end

+ 32
- 22
tweak/Apollo.xm View File

%end %end
%hook RKLink
%property(strong, nonatomic) NSString *undeleteAuthor;
-(id) author{
if ([self undeleteAuthor]){
return [self undeleteAuthor];
} else {
return %orig;
}
}
%end
%hook MarkdownRenderer %hook MarkdownRenderer
+(id) attributedStringFromHTML:(id)arg1 attributes:(id) arg2 compact:(BOOL) arg3{ +(id) attributedStringFromHTML:(id)arg1 attributes:(id) arg2 compact:(BOOL) arg3{
-(void) moreOptionsTappedWithSender:(id) arg1{ -(void) moreOptionsTappedWithSender:(id) arg1{
id commentBody = [MSHookIvar<id>(self, "comment") body];
NSString *commentBody = [MSHookIvar<RKComment *>(self, "comment") body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){ if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
shouldAddUndeleteCell = YES; shouldAddUndeleteCell = YES;
-(void) longPressedWithGestureRecognizer:(id) arg1{ -(void) longPressedWithGestureRecognizer:(id) arg1{
id commentBody = [MSHookIvar<id>(self, "comment") body];
NSString *commentBody = [MSHookIvar<RKComment *>(self, "comment") body];
if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){ if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:commentBody isDeletedOnly:isTFDeletedOnly]){
shouldAddUndeleteCell = YES; shouldAddUndeleteCell = YES;
%new %new
-(void) undeleteCellWasSelected{ -(void) undeleteCellWasSelected{
id comment = MSHookIvar<id>(self, "comment");
RKComment *comment = MSHookIvar<RKComment *>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)]; [%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
} }
%new %new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{ -(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = MSHookIvar<id>(self, "comment");
RKComment *comment = MSHookIvar<RKComment *>(self, "comment");
id bodyNode = MSHookIvar<id>(self, "bodyNode"); id bodyNode = MSHookIvar<id>(self, "bodyNode");
id authorNode = MSHookIvar<id>(self, "authorNode"); id authorNode = MSHookIvar<id>(self, "authorNode");
id authorTextNode = [authorNode subnodes][0];
NSString *author = data[@"author"]; NSString *author = data[@"author"];
NSString *body = data[@"body"]; 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])]; NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString *newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes]; 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]]; [bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
[comment setAuthor:author];
[comment setBody:body];
} }
%end %end
%new %new
-(void) undeleteCellWasSelected{ -(void) undeleteCellWasSelected{
id post = MSHookIvar<id>(self, "link");
RKLink *post = MSHookIvar<RKLink *>(self, "link");
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)]; [%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
} }
%new %new
-(void) completeUndeletePostAction:(NSDictionary *) data{ -(void) completeUndeletePostAction:(NSDictionary *) data{
RKLink *post = MSHookIvar<RKLink *>(self, "link");
id headerCellNode = [self headerCellNode]; id headerCellNode = [self headerCellNode];
id bodyNode = MSHookIvar<id>(headerCellNode, "bodyNode"); id bodyNode = MSHookIvar<id>(headerCellNode, "bodyNode");
id postInfoNode = MSHookIvar<id>(headerCellNode, "postInfoNode"); id postInfoNode = MSHookIvar<id>(headerCellNode, "postInfoNode");
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode"); id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode");
id authorTextNode = [authorNode subnodes][0];
NSString *author = data[@"author"]; NSString *author = data[@"author"];
NSString *authorTextString = [NSString stringWithFormat:@"by %@", author]; NSString *authorTextString = [NSString stringWithFormat:@"by %@", author];
NSString *body = data[@"body"]; NSString *body = data[@"body"];
id post = MSHookIvar<id>(self, "link");
//MSHookIvar<NSString*>(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])]; NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:authorTextString attributes:authorStringAttributes]; 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]]; [bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
[post setSelfText:body];
} }
%end %end

Loading…
Cancel
Save