-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathContact.m
125 lines (105 loc) · 3.74 KB
/
Contact.m
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// ContactPerson.m
// ringring.io
//
// Created by Peter Kosztolanyi on 13/01/2014.
//
//
#import "Contact.h"
#import <AddressBook/AddressBook.h>
#import "AddressBookMap.h"
#import "LinphoneHelper.h"
#import "RestKit/RestKit.h"
#import "MappingProvider.h"
#import "Status.h"
#import "User.h"
@implementation Contact
@synthesize email;
@synthesize firstName;
@synthesize lastName;
@synthesize fullName;
@synthesize image;
@synthesize hasUnreadMessages;
@synthesize isActivated;
@synthesize isLoggedIn;
@synthesize statusRefreshedAt;
// Init new contact from parameter values
- (id)initWithEmail:(NSString *)anEmail withFirstName:(NSString *)aFirstName withLastName:(NSString *)aLastName withImage:(UIImage *)anImage;
{
self = [super init];
if (self) {
// Create new contact from the parameter values
self.email = anEmail;
self.firstName = aFirstName?aFirstName:@"";
self.lastName = aLastName?aLastName:@"";
self.fullName = [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName];
// Clear empty space fullnames
if ([self.fullName isEqualToString:@" "]) self.fullName = @"";
self.image = anImage?anImage:[UIImage imageNamed:@"contacts_avatar_default.png"];
self.hasUnreadMessages = NO;
self.isActivated = NO;
self.isLoggedIn = NO;
self.statusRefreshedAt = [[NSDate date] dateByAddingTimeInterval:-120];
}
return self;
}
// Copy an existing contact
- (id)initWithContact:(Contact *)aContact
{
self = [super init];
if (self) {
self.email = aContact.email;
self.firstName = aContact.firstName?aContact.firstName:@"";
self.lastName = aContact.lastName?aContact.lastName:@"";
self.fullName = [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName];
// Clear empty space fullnames
if ([self.fullName isEqualToString:@" "]) self.fullName = @"";
self.image = aContact.image?aContact.image:[UIImage imageNamed:@"contacts_avatar_default.png"];
self.hasUnreadMessages = NO;
self.isActivated = NO;
self.isLoggedIn = NO;
self.statusRefreshedAt = [[NSDate date] dateByAddingTimeInterval:-120];
}
return self;
}
// Init new contact with default values
- (id)initWithDefault:(NSString *)anEmail
{
self = [super init];
if (self) {
self.email = anEmail;
self.firstName = NSLocalizedString(@"UNKNOWN", nil);
self.lastName = NSLocalizedString(@"UNKNOWN", nil);
self.fullName = NSLocalizedString(@"UNKNOWN", nil);
self.image = [UIImage imageNamed:@"contacts_avatar_default.png"];
self.hasUnreadMessages = NO;
self.isActivated = NO;
self.isLoggedIn = NO;
self.statusRefreshedAt = [[NSDate date] dateByAddingTimeInterval:-120];
}
return self;
}
// Contact details to string
- (NSString *)description {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
return [NSString stringWithFormat:@"email : [%@]\n\
firstName : [%@]\n\
lastName : [%@]\n\
fullName : [%@]\n\
image : %@\n\
hasUnreadMessages: %@\n\
isActivated : %@\n\
isLoggedIn : %@\n\
statusRefreshedAt: %@",
[self email],
[self firstName],
[self lastName],
[self fullName],
[self image]?@"Found":@"Not found",
[self hasUnreadMessages]?@"YES":@"NO",
[self isActivated]?@"YES":@"NO",
[self isLoggedIn]?@"YES":@"NO",
[formatter stringFromDate:[self statusRefreshedAt]]];
}
@end