Commands.ts 2.67 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2
import * as _ from 'lodash';
import { NativeCommandsSender } from '../adapters/NativeCommandsSender';
3
import { Notification } from '../DTO/Notification';
4 5
import { NotificationCategory } from '../interfaces/NotificationCategory';
import { NotificationPermissions } from '../interfaces/NotificationPermissions';
6
import { UniqueIdProvider } from '../adapters/UniqueIdProvider';
yogevbd's avatar
yogevbd committed
7 8 9

export class Commands {
  constructor(
10 11
    private readonly nativeCommandsSender: NativeCommandsSender,
    private readonly uniqueIdProvider: UniqueIdProvider
12
  ) { }
yogevbd's avatar
yogevbd committed
13

yogevbd's avatar
yogevbd committed
14 15 16
  public postLocalNotification(notification: Notification, id?: number) {
    const notificationId: number = id ? id : this.uniqueIdProvider.generate();
    const result = this.nativeCommandsSender.postLocalNotification(notification, notificationId);
yogevbd's avatar
yogevbd committed
17 18 19
    return result;
  }

20
  public async getInitialNotification(): Promise<Notification | undefined> {
yogevbd's avatar
yogevbd committed
21
    return this.nativeCommandsSender.getInitialNotification().then((payload) => {
22 23 24 25 26
      if (payload) {
        return new Notification(payload);
      }

      return undefined;
yogevbd's avatar
yogevbd committed
27
    });
yogevbd's avatar
yogevbd committed
28
  }
yogevbd's avatar
yogevbd committed
29

yogevbd's avatar
yogevbd committed
30 31 32 33
  public requestPermissions() {
    const result = this.nativeCommandsSender.requestPermissions();
    return result;
  }
yogevbd's avatar
yogevbd committed
34 35 36 37 38

  public abandonPermissions() {
    const result = this.nativeCommandsSender.abandonPermissions();
    return result;
  }
39 40 41 42 43 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

  public registerPushKit() {
    this.nativeCommandsSender.registerPushKit();
  }

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

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

  public setBadgeCount(count: number) {
    this.nativeCommandsSender.setBadgeCount(count);
  }

  public cancelLocalNotification(notificationId: string) {
    this.nativeCommandsSender.cancelLocalNotification(notificationId);
  }

  public cancelAllLocalNotifications() {
    this.nativeCommandsSender.cancelAllLocalNotifications();
  }

  public isRegisteredForRemoteNotifications(): Promise<boolean> {
    return this.nativeCommandsSender.isRegisteredForRemoteNotifications();
  }

  public checkPermissions(): Promise<NotificationPermissions> {
    return this.nativeCommandsSender.checkPermissions();
  }

  public removeAllDeliveredNotifications() {
    this.nativeCommandsSender.removeAllDeliveredNotifications();
  }

  public removeDeliveredNotifications(identifiers: Array<string>) {
    return this.nativeCommandsSender.removeDeliveredNotifications(identifiers);
  }
yogevbd's avatar
yogevbd committed
79 80 81 82

  public getDeliveredNotifications(): Array<Notification> {
    return this.nativeCommandsSender.getDeliveredNotifications();
  }
83 84

  public refreshToken() {
85
    this.nativeCommandsSender.refreshToken();
86
  }
yogevbd's avatar
yogevbd committed
87
}