RNNotificationParser.m 1.26 KB
Newer Older
yogevbd's avatar
WIP  
yogevbd committed
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
#import "RNNotificationParser.h"
#import "RCTConvert+Notifications.h"

@implementation RNNotificationParser

+ (NSDictionary *)parseNotification:(UNNotification *)notification {
    NSDictionary* notificationDict = @{@"identifier": notification.request.identifier,
                                   @"payload": [RCTConvert UNNotificationPayload:notification]
                                   };
    
    return notificationDict;
}

+ (NSDictionary *)parseNotificationResponse:(UNNotificationResponse *)response {
    NSDictionary* responseDict = @{@"payload": [RCTConvert UNNotificationPayload:response.notification], @"identifier": response.notification.request.identifier, @"action": [self parseNotificationResponseAction:response]};
    
    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