Commands.ts 2.61 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
yogevbd's avatar
yogevbd committed
12 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;
  }

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

yogevbd's avatar
yogevbd committed
26 27 28 29
  public requestPermissions() {
    const result = this.nativeCommandsSender.requestPermissions();
    return result;
  }
yogevbd's avatar
yogevbd committed
30 31 32 33 34

  public abandonPermissions() {
    const result = this.nativeCommandsSender.abandonPermissions();
    return result;
  }
35 36 37 38 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

  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
75 76 77 78

  public getDeliveredNotifications(): Array<Notification> {
    return this.nativeCommandsSender.getDeliveredNotifications();
  }
79 80 81 82

  public refreshToken() {
    return this.nativeCommandsSender.refreshToken();
  }
yogevbd's avatar
yogevbd committed
83
}