mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
c6d44e59e2
- Using same clang format file for old and new files. - Moving out all TextSecure code to allow other clients (OS X, iOS) to integrate easily TextSecure functionality. - Use TextSecure API to signup.
50 lines
1.6 KiB
Objective-C
50 lines
1.6 KiB
Objective-C
#import "CryptoTools.h"
|
|
#import "FunctionalUtil.h"
|
|
#import "NotificationTracker.h"
|
|
|
|
#define MAX_NOTIFICATIONS_TO_TRACK 100
|
|
#define NOTIFICATION_PAYLOAD_KEY @"m"
|
|
|
|
@implementation NotificationTracker {
|
|
NSMutableArray *_witnessedNotifications;
|
|
}
|
|
|
|
+ (NotificationTracker *)notificationTracker {
|
|
NotificationTracker *notificationTracker = [NotificationTracker new];
|
|
notificationTracker->_witnessedNotifications = [NSMutableArray new];
|
|
return notificationTracker;
|
|
}
|
|
|
|
- (BOOL)shouldProcessNotification:(NSDictionary *)notification {
|
|
BOOL should = ![self wasNotificationProcessed:notification];
|
|
if (should) {
|
|
[self markNotificationAsProcessed:notification];
|
|
}
|
|
return should;
|
|
}
|
|
|
|
- (void)markNotificationAsProcessed:(NSDictionary *)notification {
|
|
NSData *data = [self getIdForNotification:notification];
|
|
[_witnessedNotifications insertObject:data atIndex:0];
|
|
|
|
while (MAX_NOTIFICATIONS_TO_TRACK < _witnessedNotifications.count) {
|
|
[_witnessedNotifications removeLastObject];
|
|
}
|
|
}
|
|
|
|
- (BOOL)wasNotificationProcessed:(NSDictionary *)notification {
|
|
NSData *data = [self getIdForNotification:notification];
|
|
|
|
return [_witnessedNotifications any:^int(NSData *previousData) {
|
|
return [data isEqualToData:previousData];
|
|
}];
|
|
}
|
|
|
|
// Uniquely Identify a notification by the hash of the message payload.
|
|
- (NSData *)getIdForNotification:(NSDictionary *)notification {
|
|
NSData *data = [notification[NOTIFICATION_PAYLOAD_KEY] dataUsingEncoding:NSUTF8StringEncoding];
|
|
NSData *notificationHash = [data hashWithSha256];
|
|
return notificationHash;
|
|
}
|
|
|
|
@end
|