summaryrefslogtreecommitdiff
path: root/Juick/Model/Message.m
blob: afc01af86566221eaf7be029d6d60c37c1f643e4 (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
//
//  Message.m
//  Juick
//
//  Created by Vitaly Takmazov on 29.10.13.
//  Copyright (c) 2013 com.juick. All rights reserved.
//

#import "Message.h"

@implementation Message

+ (Message *) fromJSON:(NSDictionary *)jsonData {
    Message * message = [Message new];
    message.mid = jsonData[@"mid"];
    message.rid = jsonData[@"rid"];
    message.text = jsonData[@"body"];
    message.attach = jsonData[@"photo"][@"small"];
    message.repliesCount = jsonData[@"replies"];
    message.repliesBy = jsonData[@"repliesby"];
    message.user = [User fromJSON:jsonData[@"user"]];
    message.timestamp = jsonData[@"timestamp"];
    message.service = [jsonData[@"service"] boolValue];
    message.unread = [jsonData[@"unread"] boolValue];
    message.tags = jsonData[@"tags"];
    NSMutableArray *entitiesArray = [NSMutableArray new];
    for (NSDictionary *entityData in jsonData[@"entities"]) {
        [entitiesArray addObject:[Entity fromJSON:entityData]];
    }
    message.entities = [entitiesArray copy];
    message.attachment = [Attachment fromJSON:jsonData[@"attachment"]];
    return message;
}
@end