NativeCommandsSender.ts 3.02 KB
Newer Older
yogevbd's avatar
yogevbd committed
1
import { NativeModules } from 'react-native';
yogevbd's avatar
yogevbd committed
2
import { Notification, NotificationCategory, NotificationPermissions, NotificationCompletion } from '../interfaces/Notification';
yogevbd's avatar
yogevbd committed
3 4

interface NativeCommandsModule {
5 6 7 8 9 10 11 12 13 14 15 16 17 18
  getInitialNotification(): Promise<Notification>;
  localNotification(notification: Notification, id: string): void;
  requestPermissions(): void;
  abandonPermissions(): void;
  registerPushKit(): void;
  getBadgeCount(): Promise<number>;
  setBadgeCount(count: number): void;
  cancelLocalNotification(notificationId: string): void;
  cancelAllLocalNotifications(): void;
  isRegisteredForRemoteNotifications(): Promise<boolean>;
  checkPermissions(): Promise<NotificationPermissions>;
  removeDeliveredNotifications(identifiers: Array<string>): void;
  removeAllDeliveredNotifications(): void;
  setCategories(categories: [NotificationCategory?]): void;
yogevbd's avatar
yogevbd committed
19 20
  finishPresentingNotification(notificationId: string, callback: NotificationCompletion): void;
  finishHandlingAction(notificationId: string): void;
yogevbd's avatar
yogevbd committed
21 22 23 24 25 26 27 28 29 30 31 32
}

export class NativeCommandsSender {
  private readonly nativeCommandsModule: NativeCommandsModule;
  constructor() {
    this.nativeCommandsModule = NativeModules.RNBridgeModule;
  }

  sendLocalNotification(notification: Notification, id: string) {
    return this.nativeCommandsModule.localNotification(notification, id);
  }

yogevbd's avatar
yogevbd committed
33
  getInitialNotification(): Promise<Notification> {
yogevbd's avatar
yogevbd committed
34 35 36 37
    return this.nativeCommandsModule.getInitialNotification();
  }
  
  requestPermissions() {
38
    return this.nativeCommandsModule.requestPermissions();
yogevbd's avatar
yogevbd committed
39
  }
yogevbd's avatar
yogevbd committed
40 41 42 43

  abandonPermissions() {
    return this.nativeCommandsModule.abandonPermissions();
  }
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

  registerPushKit() {
    return this.nativeCommandsModule.registerPushKit();
  }

  setCategories(categories: [NotificationCategory?]) {
    this.nativeCommandsModule.setCategories(categories);
  }

  getBadgeCount(): Promise<number> {
    return this.nativeCommandsModule.getBadgeCount();
  }

  setBadgeCount(count: number) {
    this.nativeCommandsModule.setBadgeCount(count);
  }

  cancelLocalNotification(notificationId: string) {
    this.nativeCommandsModule.cancelLocalNotification(notificationId);
  }

  cancelAllLocalNotifications() {
    this.nativeCommandsModule.cancelAllLocalNotifications();
  }

  isRegisteredForRemoteNotifications(): Promise<any> {
    return this.nativeCommandsModule.isRegisteredForRemoteNotifications();
  }

  checkPermissions() {
    return this.nativeCommandsModule.checkPermissions();
  }

  removeAllDeliveredNotifications() {
    return this.nativeCommandsModule.removeAllDeliveredNotifications();
  }

  removeDeliveredNotifications(identifiers: Array<string>) {
    return this.nativeCommandsModule.removeDeliveredNotifications(identifiers);
  }
yogevbd's avatar
yogevbd committed
84 85 86 87 88 89 90 91

  finishPresentingNotification(notificationId: string, notificationCompletion: NotificationCompletion): void {
    this.nativeCommandsModule.finishPresentingNotification(notificationId, notificationCompletion);
  }

  finishHandlingAction(notificationId: string): void {
    this.nativeCommandsModule.finishHandlingAction(notificationId);
  }
yogevbd's avatar
yogevbd committed
92
}