RNNotificationParser.m 1.07 KB
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
1
#import "RNNotificationParser.h"
2
#import "RCTConvert+RNNotifications.h"
yogevbd's avatar
WIP  
yogevbd committed
3 4 5 6

@implementation RNNotificationParser

+ (NSDictionary *)parseNotification:(UNNotification *)notification {
yogevbd's avatar
yogevbd committed
7
    return [RCTConvert UNNotificationPayload:notification];
yogevbd's avatar
WIP  
yogevbd committed
8 9 10
}

+ (NSDictionary *)parseNotificationResponse:(UNNotificationResponse *)response {
yogevbd's avatar
yogevbd committed
11
    NSDictionary* responseDict = @{@"notification": [RCTConvert UNNotificationPayload:response.notification], @"identifier": response.notification.request.identifier, @"action": [self parseNotificationResponseAction:response]};
yogevbd's avatar
WIP  
yogevbd committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    
    return responseDict;
}

+ (NSDictionary *)parseNotificationResponseAction:(UNNotificationResponse *)response {
    NSMutableDictionary* responseAction = [NSMutableDictionary dictionaryWithDictionary:@{@"identifier": response.actionIdentifier}];

    NSString* responseText = [response isKindOfClass:[UNTextInputNotificationResponse class]] ? ((UNTextInputNotificationResponse *)response).userText : nil;
    if (responseText) {
        [responseAction setObject:responseText forKey:@"text"];
    }
    
    return responseAction;
}

@end