forked from Kieran/zap.stream
fix: don't add duplicate emoji tags
This commit is contained in:
parent
4aafb19f7e
commit
a3c486d9e4
@ -186,20 +186,26 @@ function WriteMessage({ link }: { link: NostrLink }) {
|
|||||||
async function sendChatMessage() {
|
async function sendChatMessage() {
|
||||||
const pub = await EventPublisher.nip7();
|
const pub = await EventPublisher.nip7();
|
||||||
if (chat.length > 1) {
|
if (chat.length > 1) {
|
||||||
let messageEmojis: string[][] = [];
|
let emojiNames = new Set();
|
||||||
|
|
||||||
for (const name of names) {
|
for (const name of names) {
|
||||||
if (chat.includes(`:${name}:`)) {
|
if (chat.includes(`:${name}:`)) {
|
||||||
const e = emojis.find((t) => t.at(1) === name);
|
emojiNames.add(name);
|
||||||
messageEmojis.push(e as string[]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reply = await pub?.generic((eb) => {
|
const reply = await pub?.generic((eb) => {
|
||||||
|
const emoji = [...emojiNames].map((name) =>
|
||||||
|
emojis.find((e) => e.at(1) === name)
|
||||||
|
);
|
||||||
eb.kind(1311 as EventKind)
|
eb.kind(1311 as EventKind)
|
||||||
.content(chat)
|
.content(chat)
|
||||||
.tag(["a", `${link.kind}:${link.author}:${link.id}`, "", "root"])
|
.tag(["a", `${link.kind}:${link.author}:${link.id}`, "", "root"])
|
||||||
.processContent();
|
.processContent();
|
||||||
for (const e of messageEmojis) {
|
for (const e of emoji) {
|
||||||
eb.tag(e);
|
if (e) {
|
||||||
|
eb.tag(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return eb;
|
return eb;
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@ function extractEmoji(fragments: Fragment[], tags: string[][]) {
|
|||||||
return fragments
|
return fragments
|
||||||
.map((f) => {
|
.map((f) => {
|
||||||
if (typeof f === "string") {
|
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);
|
const t = tags.find((a) => a[0] === "emoji" && a[1] === i);
|
||||||
if (t) {
|
if (t) {
|
||||||
return <Emoji name={t[1]} url={t[2]} />;
|
return <Emoji name={t[1]} url={t[2]} />;
|
||||||
|
Loading…
Reference in New Issue
Block a user