UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

42 lines (41 loc) 1.63 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.isSystemEmoji = void 0; exports.getEmojiImageUrl = getEmojiImageUrl; exports.getEmojiName = getEmojiName; exports.parseEmojiNamesFromText = parseEmojiNamesFromText; const emojis_1 = require("@mattermost/types/emojis"); Object.defineProperty(exports, "isSystemEmoji", { enumerable: true, get: function () { return emojis_1.isSystemEmoji; } }); const client_1 = require("mattermost-redux/client"); function getEmojiImageUrl(emoji) { // If its the mattermost custom emoji if (!(0, emojis_1.isSystemEmoji)(emoji) && emoji.id === 'mattermost') { return client_1.Client4.getSystemEmojiImageUrl('mattermost'); } if ((0, emojis_1.isSystemEmoji)(emoji)) { const emojiUnified = emoji?.unified?.toLowerCase() ?? ''; const filename = emojiUnified || emoji.short_names[0]; return client_1.Client4.getSystemEmojiImageUrl(filename); } return client_1.Client4.getEmojiRoute(emoji.id) + '/image'; } function getEmojiName(emoji) { return (0, emojis_1.isSystemEmoji)(emoji) ? emoji.short_name : emoji.name; } function parseEmojiNamesFromText(text) { if (!text.includes(':')) { return []; } const pattern = /:([A-Za-z0-9_-]+):/gi; const customEmojis = new Set(); let match; while ((match = pattern.exec(text)) !== null) { if (!match) { continue; } customEmojis.add(match[1]); } return Array.from(customEmojis); }