feat: note mentions

This commit is contained in:
Alejandro Gomez 2023-01-23 16:31:59 +01:00
parent cecd8ba586
commit 002082d345
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
2 changed files with 14 additions and 3 deletions

View File

@ -10,7 +10,7 @@ Snort supports the following NIP's
- [x] NIP-05: Mapping Nostr keys to DNS-based internet identifiers
- [ ] NIP-06: Basic key derivation from mnemonic seed phrase
- [x] NIP-07: `window.nostr` capability for web browsers
- [ ] NIP-08: Handling Mentions
- [x] NIP-08: Handling Mentions
- [x] NIP-09: Event Deletion
- [x] NIP-10: Conventions for clients' use of `e` and `p` tags in text events
- [ ] NIP-11: Relay Information Document

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