// // MessageCell.m // Juick // // Created by Vitaly Takmazov on 14/08/16. // Copyright © 2016 com.juick. All rights reserved. // #import "MessageCell.h" @import YYWebImage; @import DateTools; @import MWFeedParser; #import "ColorScheme.h" @implementation MessageCell - (void)awakeFromNib { [super awakeFromNib]; self.text.enabledTextCheckingTypes = NSTextCheckingTypeLink; self.text.delegate = self; self.text.linkAttributes = @{ (id)kCTForegroundColorAttributeName: [ColorScheme linkColor], (id)kCTUnderlineStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle] }; } - (void) setMessage:(Message *)msg { _message = msg; self.avatar.yy_imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://i.juick.com/a/%d.png", [msg.user.uid intValue]]]; self.title.text = msg.user.uname; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; self.timestamp.text = [[formatter dateFromString:msg.timestamp] timeAgoSinceNow]; NSUInteger count = [msg.repliesCount unsignedIntegerValue]; if (count > 0) { if ([msg.repliesBy length] > 0) { self.summary.text = [NSString stringWithFormat:@"%@ replies by %@", msg.repliesCount, msg.repliesBy]; } else { self.summary.text = [NSString stringWithFormat:@"%@ replies", msg.repliesCount]; } } else { self.summary.text = nil; } self.text.text = [msg.text stringByDecodingHTMLEntities]; [self.tags removeAllTags]; if ([msg.tags count] > 0) { [msg.tags enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [self.tags addTag:obj]; }]; } } -(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { [[UIApplication sharedApplication] openURL:url]; } @end