diff --git a/src/element/live-chat.tsx b/src/element/live-chat.tsx index 2aa6691..ece4367 100644 --- a/src/element/live-chat.tsx +++ b/src/element/live-chat.tsx @@ -186,20 +186,26 @@ function WriteMessage({ link }: { link: NostrLink }) { async function sendChatMessage() { const pub = await EventPublisher.nip7(); if (chat.length > 1) { - let messageEmojis: string[][] = []; + let emojiNames = new Set(); + for (const name of names) { if (chat.includes(`:${name}:`)) { - const e = emojis.find((t) => t.at(1) === name); - messageEmojis.push(e as string[]); + emojiNames.add(name); } } + const reply = await pub?.generic((eb) => { + const emoji = [...emojiNames].map((name) => + emojis.find((e) => e.at(1) === name) + ); eb.kind(1311 as EventKind) .content(chat) .tag(["a", `${link.kind}:${link.author}:${link.id}`, "", "root"]) .processContent(); - for (const e of messageEmojis) { - eb.tag(e); + for (const e of emoji) { + if (e) { + eb.tag(e); + } } return eb; }); diff --git a/src/element/text.tsx b/src/element/text.tsx index 6f6f25e..e722d55 100644 --- a/src/element/text.tsx +++ b/src/element/text.tsx @@ -14,7 +14,7 @@ function extractEmoji(fragments: Fragment[], tags: string[][]) { return fragments .map((f) => { if (typeof f === "string") { - return f.split(/:([a-zA-Z_-]):/g).map((i) => { + return f.split(/:([\w-]+):/g).map((i) => { const t = tags.find((a) => a[0] === "emoji" && a[1] === i); if (t) { return ;