notification.ios.js 1.65 KB
Newer Older
1 2 3 4 5 6 7
export default class IOSNotification {
  _data: Object;
  _alert: string | Object;
  _sound: string;
  _badge: number;
  _category: string;
  _type: string; // regular / managed
8
  _thread: string;
9 10 11 12

  constructor(notification: Object) {
    this._data = {};

yogevbd's avatar
yogevbd committed
13 14 15 16 17
    if (notification.aps &&
      notification.aps['content-available'] &&
      notification.aps['content-available'] === 1 &&
      !notification.aps.alert &&
      !notification.aps.sound &&
18 19 20 21
      notification.managedAps) {
      // managed notification
      this._alert = notification.managedAps.alert;
      this._sound = notification.managedAps.sound;
yogevbd's avatar
yogevbd committed
22
      this._badge = notification.aps.badge;
23
      this._category = notification.managedAps.category;
yogevbd's avatar
yogevbd committed
24
      this._type = 'managed';
yogevbd's avatar
yogevbd committed
25
      this._thread = notification.aps['thread-id'];
26
    } else if (
yogevbd's avatar
yogevbd committed
27 28
      notification.aps &&
      notification.aps.alert) {
29
      // regular notification
yogevbd's avatar
yogevbd committed
30 31 32
      this._alert = notification.aps.alert;
      this._sound = notification.aps.sound;
      this._badge = notification.aps.badge;
yogevbd's avatar
WIP  
yogevbd committed
33
      this._category = notification.category;
yogevbd's avatar
yogevbd committed
34
      this._type = 'regular';
yogevbd's avatar
WIP  
yogevbd committed
35
      this._thread = notification.thread;
36 37
    }

yogevbd's avatar
WIP  
yogevbd committed
38
    Object.keys(notification).filter(key => key !== 'userInfo').forEach(key => {
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
      this._data[key] = notification[key];
    });
  }

  getMessage(): ?string | ?Object {
    return this._alert;
  }

  getSound(): ?string {
    return this._sound;
  }

  getBadgeCount(): ?number {
    return this._badge;
  }

  getCategory(): ?string {
    return this._category;
  }

  getData(): ?Object {
    return this._data;
  }

  getType(): ?string {
    return this._type;
  }
66 67 68 69

  getThread(): ?string {
    return this._thread;
  }
70
}