// Emoji support for watch chat and reactions (item 16). A curated Unicode set // across categories (dependency-free โ€” no multi-MB emoji-data bundle), plus // admin-managed custom image emojis served at /emoji/ and referenced by // :name: shortcodes. Recently-used emoji are remembered locally. import { Store } from './store'; import { rpc } from './rpc'; export interface CustomEmoji { name: string; mime: string; } export const emojiStore = new Store<{ custom: CustomEmoji[]; recent: string[]; // unicode chars or :shortcode: }>({ custom: [], recent: JSON.parse(localStorage.getItem('echoion.recentEmoji') || '[]'), }); export async function loadCustomEmojis() { try { const res = await rpc.call<{ emojis?: CustomEmoji[] }>( 'GetCustomEmojis' ); emojiStore.set({ custom: (res && res.emojis) || [] }); } catch { /* not connected / not authed โ€” leave empty */ } } export function rememberEmoji(token: string) { const recent = [ token, ...emojiStore.get().recent.filter((r) => r !== token), ].slice(0, 24); emojiStore.set({ recent }); localStorage.setItem('echoion.recentEmoji', JSON.stringify(recent)); } // Curated categories of common Unicode emoji. export const EMOJI_CATEGORIES: Array<{ label: string; emoji: string[] }> = [ { label: 'Smileys', emoji: [ '๐Ÿ˜€', '๐Ÿ˜', '๐Ÿ˜‚', '๐Ÿคฃ', '๐Ÿ˜Š', '๐Ÿ˜‡', '๐Ÿ™‚', '๐Ÿ˜‰', '๐Ÿ˜', '๐Ÿฅฐ', '๐Ÿ˜˜', '๐Ÿ˜œ', '๐Ÿคช', '๐Ÿ˜Ž', '๐Ÿคฉ', '๐Ÿฅณ', '๐Ÿ˜', '๐Ÿ˜’', '๐Ÿ˜”', '๐Ÿ˜ž', '๐Ÿ˜ข', '๐Ÿ˜ญ', '๐Ÿ˜ค', '๐Ÿ˜ ', '๐Ÿ˜ก', '๐Ÿคฌ', '๐Ÿคฏ', '๐Ÿ˜ณ', '๐Ÿฅต', '๐Ÿฅถ', '๐Ÿ˜ฑ', '๐Ÿ˜จ', '๐Ÿค—', '๐Ÿค”', '๐Ÿคซ', '๐Ÿคฅ', '๐Ÿ˜ด', '๐Ÿคค', '๐Ÿ˜ท', '๐Ÿค’', ], }, { label: 'Gestures', emoji: [ '๐Ÿ‘', '๐Ÿ‘Ž', '๐Ÿ‘Œ', 'โœŒ๏ธ', '๐Ÿคž', '๐ŸคŸ', '๐Ÿค˜', '๐Ÿ‘Š', 'โœŠ', '๐Ÿ™Œ', '๐Ÿ‘', '๐Ÿ™', '๐Ÿ’ช', '๐Ÿ‘€', '๐Ÿ‘‹', '๐Ÿค™', '๐Ÿ’…', '๐Ÿ––', '๐Ÿซถ', '๐Ÿค', ], }, { label: 'Hearts', emoji: [ 'โค๏ธ', '๐Ÿงก', '๐Ÿ’›', '๐Ÿ’š', '๐Ÿ’™', '๐Ÿ’œ', '๐Ÿ–ค', '๐Ÿค', '๐Ÿ’”', 'โฃ๏ธ', '๐Ÿ’•', '๐Ÿ’ž', '๐Ÿ’“', '๐Ÿ’—', '๐Ÿ’–', '๐Ÿ’˜', '๐Ÿ’', 'โœจ', '๐Ÿ’ฏ', '๐Ÿ”ฅ', ], }, { label: 'Fun', emoji: [ '๐ŸŽ‰', '๐ŸŽŠ', '๐Ÿฅ‚', '๐Ÿป', '๐Ÿ•', '๐Ÿฟ', '๐ŸŽฎ', '๐ŸŽง', '๐ŸŽต', '๐ŸŽธ', 'โšก', '๐ŸŒŸ', '๐Ÿ’ฅ', '๐Ÿ‘‘', '๐Ÿš€', '๐Ÿ†', '๐ŸŽฏ', '๐Ÿ’Ž', '๐ŸŒˆ', 'โ˜€๏ธ', ], }, ]; // Render a chat message: plain text with :name: custom-emoji shortcodes // replaced by tags. Returns React nodes (text is auto-escaped by React). export function renderChatText(text: string): (string | EmojiToken)[] { const out: (string | EmojiToken)[] = []; const re = /:([a-z0-9_]{1,32}):/g; const custom = new Set(emojiStore.get().custom.map((c) => c.name)); let last = 0; let m: RegExpExecArray | null; while ((m = re.exec(text)) !== null) { if (!custom.has(m[1])) continue; if (m.index > last) out.push(text.slice(last, m.index)); out.push({ emojiName: m[1] }); last = m.index + m[0].length; } if (last < text.length) out.push(text.slice(last)); return out; } export interface EmojiToken { emojiName: string; }