2018-03-05 08:28:13 +00:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
* AndroidChannel representation wrapper
|
|
|
|
*/
|
2018-03-09 11:09:20 +00:00
|
|
|
import { Importance, Visibility } from './types';
|
2018-03-05 08:28:13 +00:00
|
|
|
import type { ImportanceType, VisibilityType } from './types';
|
|
|
|
|
|
|
|
type NativeAndroidChannel = {|
|
|
|
|
bypassDnd?: boolean,
|
|
|
|
channelId: string,
|
|
|
|
description?: string,
|
|
|
|
group?: string,
|
|
|
|
importance: ImportanceType,
|
|
|
|
lightColor?: string,
|
2018-03-31 14:42:14 +00:00
|
|
|
lightsEnabled?: boolean,
|
2018-03-05 08:28:13 +00:00
|
|
|
lockScreenVisibility?: VisibilityType,
|
|
|
|
name: string,
|
|
|
|
showBadge?: boolean,
|
|
|
|
sound?: string,
|
2018-03-31 14:42:14 +00:00
|
|
|
vibrationEnabled?: boolean,
|
2018-03-05 08:28:13 +00:00
|
|
|
vibrationPattern?: number[],
|
|
|
|
|};
|
|
|
|
|
|
|
|
export default class AndroidChannel {
|
|
|
|
_bypassDnd: boolean | void;
|
|
|
|
_channelId: string;
|
|
|
|
_description: string | void;
|
|
|
|
_group: string | void;
|
|
|
|
_importance: ImportanceType;
|
|
|
|
_lightColor: string | void;
|
2018-03-31 14:42:14 +00:00
|
|
|
_lightsEnabled: boolean | void;
|
2018-03-05 08:28:13 +00:00
|
|
|
_lockScreenVisibility: VisibilityType;
|
|
|
|
_name: string;
|
|
|
|
_showBadge: boolean | void;
|
|
|
|
_sound: string | void;
|
2018-03-31 14:42:14 +00:00
|
|
|
_vibrationEnabled: boolean | void;
|
2018-03-05 08:28:13 +00:00
|
|
|
_vibrationPattern: number[] | void;
|
|
|
|
|
2018-03-09 11:09:20 +00:00
|
|
|
constructor(channelId: string, name: string, importance: ImportanceType) {
|
|
|
|
if (!Object.values(Importance).includes(importance)) {
|
|
|
|
throw new Error(`AndroidChannel() Invalid Importance: ${importance}`);
|
|
|
|
}
|
|
|
|
this._channelId = channelId;
|
|
|
|
this._name = name;
|
|
|
|
this._importance = importance;
|
|
|
|
}
|
|
|
|
|
2018-03-05 08:28:13 +00:00
|
|
|
get bypassDnd(): ?boolean {
|
|
|
|
return this._bypassDnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
get channelId(): string {
|
|
|
|
return this._channelId;
|
|
|
|
}
|
|
|
|
|
|
|
|
get description(): ?string {
|
|
|
|
return this._description;
|
|
|
|
}
|
|
|
|
|
|
|
|
get group(): ?string {
|
|
|
|
return this._group;
|
|
|
|
}
|
|
|
|
|
|
|
|
get importance(): ImportanceType {
|
|
|
|
return this._importance;
|
|
|
|
}
|
|
|
|
|
|
|
|
get lightColor(): ?string {
|
|
|
|
return this._lightColor;
|
|
|
|
}
|
|
|
|
|
2018-03-31 14:42:14 +00:00
|
|
|
get lightsEnabled(): ?boolean {
|
|
|
|
return this._lightsEnabled;
|
|
|
|
}
|
|
|
|
|
2018-03-05 08:28:13 +00:00
|
|
|
get lockScreenVisibility(): ?VisibilityType {
|
|
|
|
return this._lockScreenVisibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
get name(): string {
|
|
|
|
return this._name;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showBadge(): ?boolean {
|
|
|
|
return this._showBadge;
|
|
|
|
}
|
|
|
|
|
|
|
|
get sound(): ?string {
|
|
|
|
return this._sound;
|
|
|
|
}
|
|
|
|
|
2018-03-31 14:42:14 +00:00
|
|
|
get vibrationEnabled(): ?boolean {
|
|
|
|
return this._vibrationEnabled;
|
|
|
|
}
|
|
|
|
|
2018-03-05 08:28:13 +00:00
|
|
|
get vibrationPattern(): ?(number[]) {
|
|
|
|
return this._vibrationPattern;
|
|
|
|
}
|
|
|
|
|
2018-03-31 14:42:14 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param lightsEnabled
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
enableLights(lightsEnabled: boolean): AndroidChannel {
|
|
|
|
this._lightsEnabled = lightsEnabled;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param vibrationEnabled
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
enableVibration(vibrationEnabled: boolean): AndroidChannel {
|
|
|
|
this._vibrationEnabled = vibrationEnabled;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-03-05 08:28:13 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param bypassDnd
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setBypassDnd(bypassDnd: boolean): AndroidChannel {
|
|
|
|
this._bypassDnd = bypassDnd;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param description
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setDescription(description: string): AndroidChannel {
|
|
|
|
this._description = description;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param group
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setGroup(groupId: string): AndroidChannel {
|
|
|
|
this._group = groupId;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param lightColor
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setLightColor(lightColor: string): AndroidChannel {
|
|
|
|
this._lightColor = lightColor;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param lockScreenVisibility
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setLockScreenVisibility(
|
|
|
|
lockScreenVisibility: VisibilityType
|
|
|
|
): AndroidChannel {
|
2018-03-09 11:09:20 +00:00
|
|
|
if (!Object.values(Visibility).includes(lockScreenVisibility)) {
|
|
|
|
throw new Error(
|
|
|
|
`AndroidChannel:setLockScreenVisibility Invalid Visibility: ${lockScreenVisibility}`
|
|
|
|
);
|
|
|
|
}
|
2018-03-05 08:28:13 +00:00
|
|
|
this._lockScreenVisibility = lockScreenVisibility;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param showBadge
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setShowBadge(showBadge: boolean): AndroidChannel {
|
|
|
|
this._showBadge = showBadge;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param sound
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setSound(sound: string): AndroidChannel {
|
|
|
|
this._sound = sound;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param vibrationPattern
|
|
|
|
* @returns {AndroidChannel}
|
|
|
|
*/
|
|
|
|
setVibrationPattern(vibrationPattern: number[]): AndroidChannel {
|
|
|
|
this._vibrationPattern = vibrationPattern;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
build(): NativeAndroidChannel {
|
|
|
|
if (!this._channelId) {
|
|
|
|
throw new Error('AndroidChannel: Missing required `channelId` property');
|
|
|
|
} else if (!this._importance) {
|
|
|
|
throw new Error('AndroidChannel: Missing required `importance` property');
|
|
|
|
} else if (!this._name) {
|
|
|
|
throw new Error('AndroidChannel: Missing required `name` property');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
bypassDnd: this._bypassDnd,
|
|
|
|
channelId: this._channelId,
|
|
|
|
description: this._description,
|
|
|
|
group: this._group,
|
|
|
|
importance: this._importance,
|
|
|
|
lightColor: this._lightColor,
|
2018-03-31 14:42:14 +00:00
|
|
|
lightsEnabled: this._lightsEnabled,
|
2018-03-05 08:28:13 +00:00
|
|
|
lockScreenVisibility: this._lockScreenVisibility,
|
|
|
|
name: this._name,
|
|
|
|
showBadge: this._showBadge,
|
|
|
|
sound: this._sound,
|
2018-03-31 14:42:14 +00:00
|
|
|
vibrationEnabled: this._vibrationEnabled,
|
2018-03-05 08:28:13 +00:00
|
|
|
vibrationPattern: this._vibrationPattern,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|