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

137 lines (97 loc) 4.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNative = require("react-native"); var _AndroidChannel = _interopRequireDefault(require("./AndroidChannel")); var _AndroidChannelGroup = _interopRequireDefault(require("./AndroidChannelGroup")); var _native = require("../../utils/native"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 AndroidNotifications { constructor(notifications) { _defineProperty(this, "_notifications", void 0); this._notifications = notifications; } createChannel(channel) { if (_reactNative.Platform.OS === 'android') { if (!(channel instanceof _AndroidChannel.default)) { throw new Error(`AndroidNotifications:createChannel expects an 'AndroidChannel' but got type ${typeof channel}`); } return (0, _native.getNativeModule)(this._notifications).createChannel(channel.build()); } return Promise.resolve(); } createChannelGroup(channelGroup) { if (_reactNative.Platform.OS === 'android') { if (!(channelGroup instanceof _AndroidChannelGroup.default)) { throw new Error(`AndroidNotifications:createChannelGroup expects an 'AndroidChannelGroup' but got type ${typeof channelGroup}`); } return (0, _native.getNativeModule)(this._notifications).createChannelGroup(channelGroup.build()); } return Promise.resolve(); } createChannelGroups(channelGroups) { if (_reactNative.Platform.OS === 'android') { if (!Array.isArray(channelGroups)) { throw new Error(`AndroidNotifications:createChannelGroups expects an 'Array' but got type ${typeof channelGroups}`); } const nativeChannelGroups = []; for (let i = 0; i < channelGroups.length; i++) { const channelGroup = channelGroups[i]; if (!(channelGroup instanceof _AndroidChannelGroup.default)) { throw new Error(`AndroidNotifications:createChannelGroups expects array items of type 'AndroidChannelGroup' but got type ${typeof channelGroup}`); } nativeChannelGroups.push(channelGroup.build()); } return (0, _native.getNativeModule)(this._notifications).createChannelGroups(nativeChannelGroups); } return Promise.resolve(); } createChannels(channels) { if (_reactNative.Platform.OS === 'android') { if (!Array.isArray(channels)) { throw new Error(`AndroidNotifications:createChannels expects an 'Array' but got type ${typeof channels}`); } const nativeChannels = []; for (let i = 0; i < channels.length; i++) { const channel = channels[i]; if (!(channel instanceof _AndroidChannel.default)) { throw new Error(`AndroidNotifications:createChannels expects array items of type 'AndroidChannel' but got type ${typeof channel}`); } nativeChannels.push(channel.build()); } return (0, _native.getNativeModule)(this._notifications).createChannels(nativeChannels); } return Promise.resolve(); } removeDeliveredNotificationsByTag(tag) { if (_reactNative.Platform.OS === 'android') { if (typeof tag !== 'string') { throw new Error(`AndroidNotifications:removeDeliveredNotificationsByTag expects an 'string' but got type ${typeof tag}`); } return (0, _native.getNativeModule)(this._notifications).removeDeliveredNotificationsByTag(tag); } return Promise.resolve(); } deleteChannelGroup(groupId) { if (_reactNative.Platform.OS === 'android') { if (typeof groupId !== 'string') { throw new Error(`AndroidNotifications:deleteChannelGroup expects an 'string' but got type ${typeof groupId}`); } return (0, _native.getNativeModule)(this._notifications).deleteChannelGroup(groupId); } return Promise.resolve(); } deleteChannel(channelId) { if (_reactNative.Platform.OS === 'android') { if (typeof channelId !== 'string') { throw new Error(`AndroidNotifications:deleteChannel expects an 'string' but got type ${typeof channelId}`); } return (0, _native.getNativeModule)(this._notifications).deleteChannel(channelId); } return Promise.resolve(); } } exports.default = AndroidNotifications;