feat: note mentions #125

Merged
verbiricha merged 3 commits from nip08 into main 2023-01-23 17:22:48 +00:00
2 changed files with 14 additions and 3 deletions
Showing only changes of commit 002082d345 - Show all commits

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;
v0l commented 2023-01-23 15:35:59 +00:00 (Migrated from github.com)
Review

Technically incorrect regex but i guess its fine as the try/catch will fallback

Technically incorrect regex but i guess its fine as the try/catch will fallback
}