From 8f14f77576b4f3558da27e6a564704e7d780c895 Mon Sep 17 00:00:00 2001 From: Thomas Mathews Date: Wed, 18 Jan 2023 10:20:52 -0800 Subject: [PATCH] Fix for mentions index. I read the docs more thoroughly this time... --- js/event.js | 9 +++++++++ js/ui/fmt.js | 16 ++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/js/event.js b/js/event.js index e682630..5a4af80 100644 --- a/js/event.js +++ b/js/event.js @@ -40,6 +40,15 @@ function event_get_pubkeys(ev) { return keys; } +function event_get_tag_values(ev) { + const keys = []; + for (const tag of ev.tags) { + if (tag.length >= 2) + keys.push(tag[1]); + } + return keys; +} + function event_calculate_pow(ev) { const id_bits = leading_zero_bits(ev.id) for (const tag of ev.tags) { diff --git a/js/ui/fmt.js b/js/ui/fmt.js index 9689400..ed19de7 100644 --- a/js/ui/fmt.js +++ b/js/ui/fmt.js @@ -33,7 +33,7 @@ function format_content(model, ev, show_media) { const content = (ev.kind == KIND_DM ? ev.decrypted || ev.content : ev.content) .trim(); const body = fmt_mentions(model, fmt_body(content, show_media), - event_get_tagged_pubkeys(ev)); + event_get_tag_values(ev)); let cw = get_content_warning(ev.tags) if (cw !== null) { let cwHTML = "Content Warning" @@ -51,7 +51,7 @@ function format_content(model, ev, show_media) { return body; } -function fmt_mentions(model, str, pubkeys) { +function fmt_mentions(model, str, tags) { var buf = ""; for (var i = 0; i < str.length; i++) { let c = str.charAt(i); @@ -78,14 +78,14 @@ function fmt_mentions(model, str, pubkeys) { } if (x == "") continue; - // Specification says it's 0-based, but everyone is doing 1-base - let pubkey = pubkeys[parseInt(x)]; - if (!pubkey) { - buf += "(Invalid User Mentioned)" + // Specification says it's 0-based + let ref = tags[parseInt(x)]; + if (!ref) { + buf += `#[${x}]` continue; } - let profile = model_get_profile(model, pubkey); - buf += ` + let profile = model_get_profile(model, ref); + buf += ` ${fmt_name(profile)}`; } return buf;