1// Copyright 2018-present 650 Industries. All rights reserved. 2 3#import "EXScopedNotificationSerializer.h" 4 5NS_ASSUME_NONNULL_BEGIN 6 7@implementation EXScopedNotificationSerializer 8 9+ (NSDictionary *)serializedNotificationResponse:(UNNotificationResponse *)response 10{ 11 NSDictionary *serializedResponse = [super serializedNotificationResponse:response]; 12 NSMutableDictionary *serializedResponseMutable = [serializedResponse mutableCopy]; 13 serializedResponseMutable[@"notification"] = [self serializedNotification:response.notification]; 14 15 return [serializedResponseMutable copy]; 16} 17 18+ (NSDictionary *)serializedNotification:(UNNotification *)notification 19{ 20 NSDictionary *serializedNotification = [super serializedNotification:notification]; 21 NSMutableDictionary *serializedNotificationMutable = [serializedNotification mutableCopy]; 22 serializedNotificationMutable[@"request"] = [self serializedNotificationRequest:notification.request]; 23 24 return [serializedNotificationMutable copy]; 25} 26 27+ (NSDictionary *)serializedNotificationContent:(UNNotificationRequest *)request 28{ 29 NSDictionary *serializedContent = [super serializedNotificationContent:request]; 30 NSMutableDictionary *serializedContentMutable = [serializedContent mutableCopy]; 31 serializedContentMutable[@"categoryIdentifier"] = request.content.categoryIdentifier ? [self removeCategoryIdentifierPrefix: request.content.categoryIdentifier userInfo:request.content.userInfo] : [NSNull null]; 32 33 return [serializedContentMutable copy]; 34} 35 36+ (NSString *)removeCategoryIdentifierPrefix:(NSString *)identifier userInfo:(NSDictionary *)userInfo 37{ 38 NSString *experienceId = userInfo[@"experienceId"] ?: [NSNull null]; 39 if (experienceId) { 40 NSString *scopedCategoryPrefix = [NSString stringWithFormat:@"%@-", experienceId]; 41 return [identifier stringByReplacingOccurrencesOfString:scopedCategoryPrefix withString:@""]; 42 } 43 return identifier; 44} 45 46@end 47 48NS_ASSUME_NONNULL_END 49