fix: don't add duplicate emoji tags

This commit is contained in:
Alejandro Gomez 2023-06-28 11:09:12 +02:00 committed by Kieran
parent 4aafb19f7e
commit a3c486d9e4
2 changed files with 12 additions and 6 deletions

View File

@ -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;
});

View File

@ -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 <Emoji name={t[1]} url={t[2]} />;