Fix npub mention bugs, fix slowness when parsing large posts

Switch the post parser to use the same code as the content parser. This
was causing many issues, including performance issues.

Changelog-Fixed: Fix lag when creating large posts
Changelog-Fixed: Fix npub mentions failing to parse in some cases
Changelog-Added: Add r tag when mentioning a url
Changelog-Removed: Remove old @ and & hex key mentions
This commit is contained in:
William Casarin
2023-07-11 09:05:45 -07:00
parent dc21b6139c
commit db2ec0a00a
11 changed files with 127 additions and 342 deletions

View File

@@ -180,9 +180,9 @@ static int parse_invoice(struct cursor *cur, struct note_block *block) {
static int parse_mention_bech32(struct cursor *cur, struct note_block *block) {
u8 *start = cur->p;
if (!parse_str(cur, "nostr:"))
return 0;
parse_char(cur, '@');
parse_str(cur, "nostr:");
block->block.str.start = (const char *)cur->p;
if (!parse_nostr_bech32(cur, &block->block.mention_bech32.bech32)) {
@@ -231,7 +231,7 @@ int damus_parse_content(struct note_blocks *blocks, const char *content) {
}
pre_mention = cur.p;
if (cp == -1 || is_whitespace(cp) || c == '#') {
if (cp == -1 || is_boundary(cp) || c == '#') {
if (c == '#' && (parse_mention_index(&cur, &block) || parse_hashtag(&cur, &block))) {
if (!add_text_then_block(&cur, blocks, block, &start, pre_mention))
return 0;
@@ -244,7 +244,7 @@ int damus_parse_content(struct note_blocks *blocks, const char *content) {
if (!add_text_then_block(&cur, blocks, block, &start, pre_mention))
return 0;
continue;
} else if (c == 'n' && parse_mention_bech32(&cur, &block)) {
} else if ((c == 'n' || c == '@') && parse_mention_bech32(&cur, &block)) {
if (!add_text_then_block(&cur, blocks, block, &start, pre_mention))
return 0;
continue;