-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRecentContact.m
221 lines (185 loc) · 6.14 KB
/
RecentContact.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//
// RecentContact.m
// ringring.io
//
// Created by Peter Kosztolanyi on 01/02/2014.
//
//
#import "RecentContact.h"
#import "LinphoneManager.h"
#import "LinphoneHelper.h"
#import "AddressBookMap.h"
@implementation RecentContact
@synthesize recentType;
@synthesize callDirection;
@synthesize callStatus;
@synthesize callDuration;
@synthesize messageDirection;
@synthesize recentDate;
- (id)initWithCallLog:(LinphoneCallLog *)callLog withContact:(Contact *)aContact
{
Contact *contact = nil;
// Get email from call log
NSString *email = [LinphoneHelper emailFromCallLog:callLog];
// Contact is incoming parameter
if (aContact) {
contact = aContact;
}
// Contact is not defined; try to get it from the addressbook by email
else {
contact = [AddressBookMap getContactWithEmail:email];
}
// Contact found; clone the result contact
if (contact) {
self = [super initWithContact:contact];
}
// Still no contact; create adefault contact
else {
self = [super initWithDefault:email];
}
// Add Recent properties
if (self && callLog) {
self.recentType = RecentCall;
self.callDirection = (LinphoneCallDir *)linphone_call_log_get_dir(callLog);
self.callStatus = (LinphoneCallStatus *)linphone_call_log_get_status(callLog);
self.callDuration = linphone_call_log_get_duration(callLog);
self.messageDirection = NoMessage;
self.recentDate = [NSDate dateWithTimeIntervalSince1970:linphone_call_log_get_start_date(callLog)];
}
return self;
}
- (id)initWithMessageLog:(Message *)message withContact:(Contact *)aContact;
{
Contact *contact = nil;
// Get email from message log
NSString *email = message.email;
// Contact is incoming parameter
if (aContact) {
contact = aContact;
}
// Contact is not defined; try to get it from the addressbook by email
else {
contact = [AddressBookMap getContactWithEmail:email];
}
// Contact found; clone the result contact
if (contact) {
self = [super initWithContact:contact];
}
// Still no contact; create default contact
else {
self = [super initWithDefault:email];
}
// Add Recent properties
if (self && message) {
self.recentType = RecentMessage;
self.callDirection = nil;
self.callStatus = nil;
self.callDuration = 0;
self.messageDirection = message.messageDirection;
self.recentDate = message.receivedDate;
self.hasUnreadMessages = message.hasUnreadMessages;
}
return self;
}
- (NSString *)recentTypeToString
{
NSString *recentTypeString;
switch ((RecentType)recentType) {
case RecentCall:
recentTypeString = NSLocalizedString(@"CALL", nil);
break;
case RecentMessage:
recentTypeString = NSLocalizedString(@"MESSAGE", nil);
break;
}
return recentTypeString;
}
- (NSString *)callDirectionToString
{
NSString *callDirectionString;
if (recentType == RecentCall) {
switch ((LinphoneCallDir)callDirection) {
case LinphoneCallOutgoing:
callDirectionString = NSLocalizedString(@"OUTGOING", nil);
break;
case LinphoneCallIncoming:
callDirectionString = NSLocalizedString(@"INCOMING", nil);
break;
}
}
return callDirectionString;
}
- (NSString *)callStatusToString
{
NSString *callStatusString;
if (recentType == RecentCall) {
switch ((LinphoneCallStatus)callStatus) {
case LinphoneCallAborted:
callStatusString = NSLocalizedString(@"ABORTED", nil);
break;
case LinphoneCallDeclined:
callStatusString = NSLocalizedString(@"DECLINED", nil);
break;
case LinphoneCallMissed:
callStatusString = NSLocalizedString(@"MISSED", nil);
break;
case LinphoneCallSuccess:
callStatusString = NSLocalizedString(@"SUCCESS", nil);
break;
}
}
return callStatusString;
}
- (NSString *)messageDirectionToString
{
NSString *messageDirectionString;
if (recentType == RecentMessage) {
switch ((MessageDirection)messageDirection) {
case NoMessage:
messageDirectionString = NSLocalizedString(@"NO_MESSAGE", nil);
break;
case OutgoingMessage:
messageDirectionString = NSLocalizedString(@"OUTGOING", nil);
break;
case IncomingMessage:
messageDirectionString = NSLocalizedString(@"INCOMING", nil);
break;
}
}
return messageDirectionString;
}
- (NSString *)description {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
return [NSString stringWithFormat:@"email : [%@]\n\
recentType : [%@]\n\
firstName : [%@]\n\
lastName : [%@]\n\
fullName : [%@]\n\
image : %@\n\
hasUnreadMessages: %@\n\
isActivated : %@\n\
isLoggedIn : %@\n\
statusRefreshedAt: %@\n\
callDirection : %@\n\
callStatus : %@\n\
callDuration : %d\n\
messageDirection : %@\n\
recentDate : %@",
[self email],
[self recentTypeToString],
[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]],
[self callDirectionToString],
[self callStatusToString],
callDuration,
[self messageDirectionToString],
[formatter stringFromDate:[self recentDate]]];
}
@end