forked from andrewwiik/Intelix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITXNotificationsSection.m
84 lines (76 loc) · 2.34 KB
/
ITXNotificationsSection.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
#import <Intelix/ITXNotificationsSection.h>
@implementation ITXNotificationsSection
- (id)init {
// HBLogInfo(@"Method #150");
self = [super init];
if (self) {
_notifications = [NSMutableArray new];
_identifier = @"";
_title = @"Unknown";
_recentNotificationDate = [NSDate dateWithTimeIntervalSince1970:0];
}
return self;
}
- (void)insertNotificationRequest:(NCNotificationRequest *)notification {
// HBLogInfo(@"Method #151");
if (notification) {
[_notifications insertObject:notification atIndex:0];
}
[self recomputeMostRecentDate];
}
- (void)removeNotificationRequest:(NCNotificationRequest *)notification {
// HBLogInfo(@"Method #152");
for (NSUInteger x = 0; x < [_notifications count]; x++) {
if ([_notifications[x].notificationIdentifier isEqualToString:notification.notificationIdentifier]) {
[_notifications removeObjectAtIndex:x];
[self recomputeMostRecentDate];
return;
}
}
}
- (void)modifyNotificationRequest:(NCNotificationRequest *)notification {
// HBLogInfo(@"Method #153");
for (NSUInteger x = 0; x < [_notifications count]; x++) {
if ([_notifications[x].notificationIdentifier isEqualToString:notification.notificationIdentifier]) {
[_notifications replaceObjectAtIndex:x withObject:notification];
[self recomputeMostRecentDate];
return;
}
}
}
- (NSUInteger)indexOfNotification:(NCNotificationRequest *)notification {
// HBLogInfo(@"Method #154");
for (NSUInteger x = 0; x < [_notifications count]; x++) {
if ([_notifications[x].notificationIdentifier isEqualToString:notification.notificationIdentifier]) {
return x;
}
}
return NSNotFound;
}
- (NSUInteger)count {
// HBLogInfo(@"Method #155");
return [_notifications count];
}
- (void)recomputeMostRecentDate {
// HBLogInfo(@"Method #156");
for (NCNotificationRequest *request in _notifications) {
if (request.timestamp && [request.timestamp timeIntervalSince1970] > [_recentNotificationDate timeIntervalSince1970]) {
_recentNotificationDate = request.timestamp;
}
}
}
- (NCNotificationRequest *)requestAtIndex:(NSUInteger)index {
// HBLogInfo(@"Method #157");
if (index < [_notifications count]) {
return _notifications[index];
}
return nil;
}
- (NCNotificationRequest *)notificationAtIndex:(NSUInteger)index {
// HBLogInfo(@"Method #158");
if (index < [_notifications count]) {
return _notifications[index];
}
return nil;
}
@end