all files / firebase/modules/notifications/ AndroidChannel.js

14.63% Statements 6/41
10% Branches 1/10
9.52% Functions 2/21
14.63% Lines 6/41
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 30 31 32 33 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199                                                                                                                                                                                                                                                                                                                                                                                                 
/**
 * @flow
 * AndroidChannel representation wrapper
 */
import { Importance, Visibility } from './types';
import type { ImportanceType, VisibilityType } from './types';
 
type NativeAndroidChannel = {|
  bypassDnd?: boolean,
  channelId: string,
  description?: string,
  group?: string,
  importance: ImportanceType,
  lightColor?: string,
  lockScreenVisibility?: VisibilityType,
  name: string,
  showBadge?: boolean,
  sound?: string,
  vibrationPattern?: number[],
|};
 
export default class AndroidChannel {
  _bypassDnd: boolean | void;
  _channelId: string;
  _description: string | void;
  _group: string | void;
  _importance: ImportanceType;
  _lightColor: string | void;
  _lockScreenVisibility: VisibilityType;
  _name: string;
  _showBadge: boolean | void;
  _sound: string | void;
  _vibrationPattern: number[] | void;
 
  constructor(channelId: string, name: string, importance: ImportanceType) {
    Iif (!Object.values(Importance).includes(importance)) {
      throw new Error(`AndroidChannel() Invalid Importance: ${importance}`);
    }
    this._channelId = channelId;
    this._name = name;
    this._importance = importance;
  }
 
  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;
  }
 
  get lockScreenVisibility(): ?VisibilityType {
    return this._lockScreenVisibility;
  }
 
  get name(): string {
    return this._name;
  }
 
  get showBadge(): ?boolean {
    return this._showBadge;
  }
 
  get sound(): ?string {
    return this._sound;
  }
 
  get vibrationPattern(): ?(number[]) {
    return this._vibrationPattern;
  }
 
  /**
   *
   * @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 {
    if (!Object.values(Visibility).includes(lockScreenVisibility)) {
      throw new Error(
        `AndroidChannel:setLockScreenVisibility Invalid Visibility: ${lockScreenVisibility}`
      );
    }
    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,
      lockScreenVisibility: this._lockScreenVisibility,
      name: this._name,
      showBadge: this._showBadge,
      sound: this._sound,
      vibrationPattern: this._vibrationPattern,
    };
  }
}