Fix for mentions index.

I read the docs more thoroughly this time...
This commit is contained in:
Thomas Mathews 2023-01-18 10:20:52 -08:00
parent 7ccb07ffc3
commit 8f14f77576
2 changed files with 17 additions and 8 deletions

View file

@ -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) {

View file

@ -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 += `<span class="username clickable" data-pubkey="${pubkey}">
let profile = model_get_profile(model, ref);
buf += `<span class="username clickable" data-pubkey="${ref}">
${fmt_name(profile)}</span>`;
}
return buf;