Notifications.ts 3.16 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3 4
import { NativeCommandsSender } from './adapters/NativeCommandsSender';
import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
import { Commands } from './commands/Commands';
import { EventsRegistry } from './events/EventsRegistry';
5
import { Notification, NotificationCategory } from './interfaces/Notification';
6
import { UniqueIdProvider } from './adapters/UniqueIdProvider';
yogevbd's avatar
yogevbd committed
7 8 9 10 11 12

export class NotificationsRoot {
  private readonly nativeEventsReceiver: NativeEventsReceiver;
  private readonly nativeCommandsSender: NativeCommandsSender;
  private readonly commands: Commands;
  private readonly eventsRegistry: EventsRegistry;
13
  private readonly uniqueIdProvider: UniqueIdProvider;
yogevbd's avatar
yogevbd committed
14 15 16 17

  constructor() {
    this.nativeEventsReceiver = new NativeEventsReceiver();
    this.nativeCommandsSender = new NativeCommandsSender();
18
    this.uniqueIdProvider = new UniqueIdProvider();
yogevbd's avatar
yogevbd committed
19
    this.commands = new Commands(
20 21
      this.nativeCommandsSender,
      this.uniqueIdProvider
yogevbd's avatar
yogevbd committed
22 23 24 25 26 27 28
    );
    this.eventsRegistry = new EventsRegistry(this.nativeEventsReceiver);
  }

  /**
  * Request permissions to send remote notifications - iOS only
  */
29
  public requestPermissions() {
yogevbd's avatar
yogevbd committed
30 31 32
    return this.commands.requestPermissions();
  }

33 34 35 36 37 38 39
  /**
   * registerPushKit
   */
  public registerPushKit() {
    return this.commands.registerPushKit();
  }
  
yogevbd's avatar
yogevbd committed
40 41 42
  /**
   * Reset the app to a new layout
   */
43 44
  public localNotification(notification: Notification, id: string) {
    return this.commands.sendLocalNotification(notification, id);
yogevbd's avatar
yogevbd committed
45 46 47 48 49 50 51 52 53
  }

  /**
   * 
   */
  public getInitialNotification(): Promise<Notification> {
    return this.commands.getInitialNotification();
  }

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 84 85 86 87 88 89 90 91 92
  /**
   * setCategories
   */
  public setCategories(categories: [NotificationCategory?]) {
    this.commands.setCategories(categories);
  }

  /**
   * getBadgesCount
   */
  public getBadgeCount(): Promise<number> {
    return this.commands.getBadgeCount();
  }

  /**
   * setBadgeCount
   * @param count number of the new badge count
   */
  public setBadgeCount(count: number) {
    return this.commands.setBadgeCount(count);
  }

  /**
   * cancelLocalNotification
  */
  public cancelLocalNotification(notificationId: string) {
    return this.commands.cancelLocalNotification(notificationId);
  }

  /**
   * cancelAllLocalNotifications
   */
  public cancelAllLocalNotifications() {
    this.commands.cancelAllLocalNotifications();
  }

  /**
   * isRegisteredForRemoteNotifications
   */
93 94
  public isRegisteredForRemoteNotifications(): Promise<boolean> {
    return this.commands.isRegisteredForRemoteNotifications();
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  }

  /**
   * checkPermissions
   */
  public checkPermissions() {
    return this.commands.checkPermissions();
  }

  /**
   * removeAllDeliveredNotifications
   */
  public removeAllDeliveredNotifications() {
    return this.commands.removeAllDeliveredNotifications();
  }

  /**
   * removeDeliveredNotifications
   * @param identifiers Array of notification identifiers
   */
  public removeDeliveredNotifications(identifiers: Array<string>) {
    return this.commands.removeDeliveredNotifications(identifiers);
  }

yogevbd's avatar
yogevbd committed
119 120 121 122 123 124 125
  /**
   * Obtain the events registry instance
   */
  public events(): EventsRegistry {
    return this.eventsRegistry;
  }
}