feat: note mentions

This commit is contained in:
Alejandro Gomez
2023-01-23 16:31:59 +01:00
parent cecd8ba586
commit 002082d345
2 changed files with 14 additions and 3 deletions

View File

@ -54,14 +54,25 @@ export default function useEventPublisher() {
return match
}
}
const replaceNoteId = (match: string) => {
try {
const hex = bech32ToHex(match);
const idx = ev.Tags.length;
ev.Tags.push(new Tag(["e", hex], idx));
return `#[${idx}]`
} catch (error) {
return match
}
}
const replaceHashtag = (match: string) => {
const tag = match.slice(1);
const idx = ev.Tags.length;
ev.Tags.push(new Tag(["t", tag.toLowerCase()], idx));
return match;
}
let content = msg.replace(/@npub[a-z0-9]+/g, replaceNpub);
content = content.replace(HashtagRegex, replaceHashtag);
const content = msg.replace(/@npub[a-z0-9]+/g, replaceNpub)
.replace(/note[a-z0-9]+/g, replaceNoteId)
.replace(HashtagRegex, replaceHashtag);
ev.Content = content;
}