CompletionCallbackWrapper.ts 998 Bytes
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import { NativeCommandsSender } from './NativeCommandsSender';
import { NotificationCompletion, Notification } from '../interfaces/Notification';
import { NotificationResponse } from '../interfaces/NotificationEvents';

export class CompletionCallbackWrapper {
  constructor(
    private readonly nativeCommandsSender: NativeCommandsSender
  ) {}

  public wrapReceivedCallback(callback: Function): (notification: Notification) => void {
    return (notification) => {
      const completion = (response: NotificationCompletion) => {
        this.nativeCommandsSender.finishPresentingNotification(notification.identifier, response);
      };

      callback(notification, completion);
    }
  }

  public wrapOpenedCallback(callback: Function): (response: NotificationResponse) => void {
    return (response) => {
      const completion = () => {
        this.nativeCommandsSender.finishHandlingAction(response.notification.identifier);
      };

      callback(response, completion);
    }
  }
}