1// Copyright 2018-present 650 Industries. All rights reserved.
2
3#if __has_include(<EXNotifications/EXNotificationsEmitter.h>)
4
5#import "EXScopedNotificationsEmitter.h"
6#import "EXScopedNotificationsUtils.h"
7
8@interface EXScopedNotificationsEmitter ()
9
10@property (nonatomic, strong) NSString *experienceId;
11
12@end
13
14@implementation EXScopedNotificationsEmitter
15
16- (instancetype)initWithExperienceId:(NSString *)experienceId
17{
18  if (self = [super init]) {
19    _experienceId = experienceId;
20  }
21
22  return self;
23}
24
25- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
26{
27  if ([EXScopedNotificationsUtils shouldNotification:response.notification beHandledByExperience:_experienceId]) {
28    [super userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
29    return;
30  }
31
32  completionHandler();
33}
34
35- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
36{
37  if ([EXScopedNotificationsUtils shouldNotification:notification beHandledByExperience:_experienceId]) {
38    [super userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
39    return;
40  }
41
42  completionHandler(UNNotificationPresentationOptionNone);
43}
44
45@end
46
47#endif
48