UNPKG

react-native-firebase-compiled

Version:

A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto

171 lines (131 loc) 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _utils = require("../../utils"); function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class RemoteMessage { constructor(inboundMessage) { _defineProperty(this, "_collapseKey", void 0); _defineProperty(this, "_data", void 0); _defineProperty(this, "_from", void 0); _defineProperty(this, "_messageId", void 0); _defineProperty(this, "_messageType", void 0); _defineProperty(this, "_sentTime", void 0); _defineProperty(this, "_to", void 0); _defineProperty(this, "_ttl", void 0); if (inboundMessage) { this._collapseKey = inboundMessage.collapseKey; this._data = inboundMessage.data; this._from = inboundMessage.from; this._messageId = inboundMessage.messageId; this._messageType = inboundMessage.messageType; this._sentTime = inboundMessage.sentTime; } // defaults this._data = this._data || {}; // TODO: Is this the best way to generate an ID? this._messageId = this._messageId || (0, _utils.generatePushID)(); this._ttl = 3600; } get collapseKey() { return this._collapseKey; } get data() { return this._data; } get from() { return this._from; } get messageId() { return this._messageId; } get messageType() { return this._messageType; } get sentTime() { return this._sentTime; } get to() { return this._to; } get ttl() { return this._ttl; } /** * * @param collapseKey * @returns {RemoteMessage} */ setCollapseKey(collapseKey) { this._collapseKey = collapseKey; return this; } /** * * @param data * @returns {RemoteMessage} */ setData(data = {}) { if (!(0, _utils.isObject)(data)) { throw new Error(`RemoteMessage:setData expects an object but got type '${typeof data}'.`); } this._data = data; return this; } /** * * @param messageId * @returns {RemoteMessage} */ setMessageId(messageId) { this._messageId = messageId; return this; } /** * * @param messageType * @returns {RemoteMessage} */ setMessageType(messageType) { this._messageType = messageType; return this; } /** * * @param to * @returns {RemoteMessage} */ setTo(to) { this._to = to; return this; } /** * * @param ttl * @returns {RemoteMessage} */ setTtl(ttl) { this._ttl = ttl; return this; } build() { if (!this._data) { throw new Error('RemoteMessage: Missing required `data` property'); } else if (!this._messageId) { throw new Error('RemoteMessage: Missing required `messageId` property'); } else if (!this._to) { throw new Error('RemoteMessage: Missing required `to` property'); } else if (!this._ttl) { throw new Error('RemoteMessage: Missing required `ttl` property'); } return { collapseKey: this._collapseKey, data: this._data, messageId: this._messageId, messageType: this._messageType, to: this._to, ttl: this._ttl }; } } exports.default = RemoteMessage;