This repository was archived by the owner on Jun 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDWMessage.m
More file actions
68 lines (51 loc) · 1.74 KB
/
DWMessage.m
File metadata and controls
68 lines (51 loc) · 1.74 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// DWMessage.m
// Tweeterena
//
// Created by Dominic Wroblewski on 14/11/2010.
// Copyright 2010 TerraCoding. All rights reserved.
//
#import "DWMessage.h"
@implementation DWMessage
@synthesize avatar;
@synthesize avatarURL;
@synthesize fullname;
@synthesize tweetID;
@synthesize date;
@synthesize recipient;
@synthesize msg;
@synthesize username;
- (id) initWithDictionary:(NSDictionary*)dict {
self.tweetID = [dict objectForKey:@"id_str"];
self.date = [dict objectForKey:@"created_at"];
self.recipient = [dict objectForKey:@"recipient_screen_name"];
self.msg = [dict objectForKey:@"text"];
self.username = [dict objectForKey:@"sender_screen_name"];
self.fullname = [[dict objectForKey:@"sender"] objectForKey:@"name"];
self.avatarURL = [[dict objectForKey:@"sender"] valueForKey:@"profile_image_url"];
[NSThread detachNewThreadSelector:@selector(bgThread:) toTarget:self withObject:dict];
return self;
}
-(void)bgThread:(NSDictionary *)obj
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *imageURL = [NSURL URLWithString:[[obj objectForKey:@"sender"] valueForKey:@"profile_image_url"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
NSImage *image = [[NSImage alloc] initWithData:imageData];
self.avatar = image;
[self performSelectorOnMainThread:@selector(bgThreadIsDone:) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)bgThreadIsDone:(id)obj
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"reload_table" object:nil];
}
- (NSImage *)imageFromUrl:(NSString*)url {
if (url) {
NSURL *imageURL = [NSURL URLWithString:url];
NSImage *image = [[[NSImage alloc] initWithData:[NSData dataWithContentsOfURL:imageURL]] autorelease];
return image;
}
return nil;
}
@end