1// Copyright 2018-present 650 Industries. All rights reserved.
2
3#import "EXScopedNotificationBuilder.h"
4#import "EXScopedNotificationsUtils.h"
5
6@interface EXScopedNotificationBuilder ()
7
8@property (nonatomic, strong) NSString *scopeKey;
9@property (nonatomic, assign) BOOL isInExpoGo;
10
11@end
12
13@implementation EXScopedNotificationBuilder
14
15- (instancetype)initWithScopeKey:(NSString *)scopeKey
16                       andConstantsBinding:(EXConstantsBinding *)constantsBinding
17{
18  if (self = [super init]) {
19    _scopeKey = scopeKey;
20    _isInExpoGo = [@"expo" isEqualToString:constantsBinding.appOwnership];
21  }
22
23  return self;
24}
25
26- (UNNotificationContent *)notificationContentFromRequest:(NSDictionary *)request
27{
28  UNMutableNotificationContent *content = [super notificationContentFromRequest:request];
29  NSMutableDictionary *userInfo = [content.userInfo mutableCopy];
30  if (!userInfo) {
31    userInfo = [NSMutableDictionary dictionary];
32  }
33  userInfo[@"experienceId"] = _scopeKey;
34  userInfo[@"scopeKey"] = _scopeKey;
35  [content setUserInfo:userInfo];
36
37  if (content.categoryIdentifier && _isInExpoGo) {
38    NSString *scopedCategoryIdentifier = [EXScopedNotificationsUtils scopedIdentifierFromId:content.categoryIdentifier
39                                                                              forExperience:_scopeKey];
40    [content setCategoryIdentifier:scopedCategoryIdentifier];
41  }
42
43  return content;
44}
45
46@end
47