-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChat.m
More file actions
executable file
·100 lines (87 loc) · 2.72 KB
/
Chat.m
File metadata and controls
executable file
·100 lines (87 loc) · 2.72 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// Chat.m
// Junction
//
// Created by Bobby Ren on 1/1/13.
//
//
#import "Chat.h"
#define CLASSNAME @"Chat"
@implementation Chat
@synthesize message;
@synthesize sender;
@synthesize pfObject;
@synthesize className;
@synthesize chatChannel;
@synthesize hasBeenSeen;
//@synthesize userInfo;
-(id)init {
self = [super init];
[self setClassName:CLASSNAME];
// if we init a userInfo, it must have a new/empty pfObject
// userInfo objects created from Parse are generated by initWithPFObject which uses fromPFObject
PFObject *newPFObject = [[PFObject alloc] initWithClassName:CLASSNAME];
[self setPfObject:newPFObject];
return self;
}
- (id)initWithPFObject:(PFObject *)object {
self = [super init];
if (self)
{
[self fromPFObject:object];
}
return self;
}
-(PFObject*)pfObject {
// returns current object
if (pfObject)
return pfObject;
else {
// do not allocate; returning nil should indicate need to find object
return nil;
}
return pfObject;
}
-(PFObject*)toPFObject {
// for a pulse we only need to save the pfUser and the location
// returns current pfObject but with updated coordinate and user
@try {
[self.pfObject setObject:sender forKey:@"sender"];
[self.pfObject setObject:message forKey:@"message"];
[self.pfObject setObject:chatChannel forKey:@"chatChannel"];
}
@catch (NSException *exception) {
NSLog(@"Caught exception in trying to convert to PFObject! exception: %@", exception);
return nil;
}
return self.pfObject;
}
- (id)fromPFObject:(PFObject *)pObject {
[self setPfObject:pObject];
[self setClassName:pObject.className];
[self setSender:[pObject objectForKey:@"sender"]];
[self setMessage:[pObject objectForKey:@"message"]];
[self setChatChannel:[pObject objectForKey:@"chatChannel"]];
return self;
}
-(void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.message forKey:@"message"];
[aCoder encodeObject:self.sender forKey:@"sender"];
[aCoder encodeObject:self.chatChannel forKey:@"chatChannel"];
[aCoder encodeBool:self.hasBeenSeen forKey:@"hasBeenSeen"];
// [aCoder encodeObject:self.userInfo forKey:@"userInfo"];
}
-(id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super init])) {
[self setMessage:[aDecoder decodeObjectForKey:@"message"]];
[self setSender:[aDecoder decodeObjectForKey:@"sender"]];
[self setChatChannel:[aDecoder decodeObjectForKey:@"chatChannel"]];
[self setHasBeenSeen:[aDecoder decodeBoolForKey:@"hasBeenSeen"]];
// [self setUserInfo:[aDecoder decodeObjectForKey:@"userInfo"]];
}
return self;
}
+(NSString*)getClassName {
return CLASSNAME;
}
@end