[notifications] Refactor for better support of separate messages

This commit is contained in:
Chris Bianca
2018-02-22 15:52:24 +00:00
parent 831eec82f7
commit 303cb4c428
12 changed files with 463 additions and 326 deletions

View File

@@ -7,21 +7,7 @@ import AndroidNotification from './AndroidNotification';
import IOSNotification from './IOSNotification';
import { generatePushID, isObject } from '../../utils';
import type { NativeAndroidNotification } from './AndroidNotification';
import type { NativeIOSNotification } from './IOSNotification';
import type { Schedule } from './';
type NativeNotification = {|
android?: NativeAndroidNotification,
body: string,
data: { [string]: string },
ios?: NativeIOSNotification,
notificationId: string,
schedule?: Schedule,
sound?: string,
subtitle?: string,
title: string,
|};
import type { NativeNotification } from './types';
export default class Notification {
// iOS 8/9 | 10+ | Android
@@ -34,12 +20,23 @@ export default class Notification {
_subtitle: string | void; // N/A | subtitle | subText
_title: string; // alertTitle | title | contentTitle
constructor() {
this._android = new AndroidNotification(this);
this._data = {};
this._ios = new IOSNotification(this);
// TODO: Is this the best way to generate an ID?
this._notificationId = generatePushID();
constructor(data?: NativeNotification) {
this._android = new AndroidNotification(this, data && data.android);
this._ios = new IOSNotification(this, data && data.ios);
if (data) {
this._body = data.body;
this._data = data.data;
// TODO: Is this the best way to generate an ID?
this._notificationId = data.notificationId;
this._sound = data.sound;
this._subtitle = data.subtitle;
this._title = data.title;
}
// Defaults
this._data = this._data || {};
this._notificationId = this._notificationId || generatePushID();
}
get android(): AndroidNotification {