summaryrefslogtreecommitdiff
path: root/Juick/Model/Message.m
blob: d39be5424166c07d23fc906b727e075480a6fa3b (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"];
    message.unread = jsonData[@"unread"];
    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