summaryrefslogtreecommitdiff
path: root/Juick/Views/MessageCell.m
blob: 963707c76c127daf4a5e69c212b8f3ad7c1d8a30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
//  MessageCell.m
//  Juick
//
//  Created by Vitaly Takmazov on 14/08/16.
//  Copyright © 2016 com.juick. All rights reserved.
//

#import "MessageCell.h"

@implementation MessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.text.enabledTextCheckingTypes = NSTextCheckingTypeLink;
    self.text.delegate = self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (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] timeAgo];
    if (msg.repliesCount > 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];
    if ([msg.tags count] > 0) {
        self.text.text = [[NSString alloc] initWithFormat:@"%@\n%@", [msg.tags componentsJoinedByString:@", "],
                               [msg.text stringByDecodingHTMLEntities]];
    }
}

-(void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
    [[UIApplication sharedApplication] openURL:url];
}

@end