Commands.ts 2.56 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
  public getInitialNotification(): Promise<Notification> {
yogevbd's avatar
yogevbd committed
21 22 23 24 25 26 27 28
    const result = this.nativeCommandsSender.getInitialNotification();
    return result;
  }
  
  public requestPermissions() {
    const result = this.nativeCommandsSender.requestPermissions();
    return result;
  }
yogevbd's avatar
yogevbd committed
29 30 31 32 33

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

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

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

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