UNPKG

@sendbird/uikit-react-native

Version:

Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

85 lines (84 loc) 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _uikitReactNativeFoundation = require("@sendbird/uikit-react-native-foundation"); var _InternalLocalCacheStorage = _interopRequireDefault(require("./InternalLocalCacheStorage")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } class MemoryStorage { constructor() { _defineProperty(this, "_data", {}); } async getAllKeys() { return Object.keys(this._data); } async getItem(key) { return this._data[key]; } async removeItem(key) { delete this._data[key]; } async setItem(key, value) { this._data[key] = value; } } class EmojiManager { constructor(internalStorage = new _InternalLocalCacheStorage.default(new MemoryStorage())) { this.internalStorage = internalStorage; _defineProperty(this, "emojiStorage", { container: null, get: async () => { if (!this.emojiStorage.container) { const strItem = await this.internalStorage.getItem(EmojiManager.key); if (strItem) this.emojiStorage.container = Object.freeze(JSON.parse(strItem)); } return this.emojiStorage.container; }, set: async container => { this.emojiStorage.container = Object.freeze(container); await this.internalStorage.setItem(EmojiManager.key, JSON.stringify(container)); } }); _defineProperty(this, "_emojiCategoryMap", {}); _defineProperty(this, "_allEmojiMap", {}); _defineProperty(this, "_allEmoji", []); _defineProperty(this, "init", async emojiContainer => { if (emojiContainer) await this.emojiStorage.set(emojiContainer); const container = await this.emojiStorage.get(); if (container) { for (const category of container.emojiCategories) { this._emojiCategoryMap[category.id] = category; for (const emoji of category.emojis) { this._allEmojiMap[emoji.key] = emoji; } } this._allEmoji = Object.values(this._allEmojiMap); } }); } get emojiCategoryMap() { return this._emojiCategoryMap; } get allEmojiMap() { return this._allEmojiMap; } get allEmoji() { return this._allEmoji; } getEmojiIconSource(emoji) { return emoji !== null && emoji !== void 0 && emoji.url ? { uri: emoji.url } : _uikitReactNativeFoundation.Icon.Assets.question; } get emojiHash() { var _this$emojiStorage$co; return (_this$emojiStorage$co = this.emojiStorage.container) === null || _this$emojiStorage$co === void 0 ? void 0 : _this$emojiStorage$co.emojiHash; } } _defineProperty(EmojiManager, "key", 'sendbird-uikit@emoji-manager'); var _default = exports.default = EmojiManager; //# sourceMappingURL=EmojiManager.js.map