mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
46 lines (45 loc) • 1.56 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSystemEmoji = isSystemEmoji;
exports.getEmojiImageUrl = getEmojiImageUrl;
exports.getEmojiName = getEmojiName;
exports.parseEmojiNamesFromText = parseEmojiNamesFromText;
const client_1 = require("mattermost-redux/client");
function isSystemEmoji(emoji) {
if ('category' in emoji) {
return emoji.category !== 'custom';
}
return !('id' in emoji);
}
function getEmojiImageUrl(emoji) {
// If its the mattermost custom emoji
if (!isSystemEmoji(emoji) && emoji.id === 'mattermost') {
return client_1.Client4.getSystemEmojiImageUrl('mattermost');
}
if (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 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);
}