Almost got everythign working.

Issues left to resolve:

 * Removing a reaction doesn't properly remove it from UI, but the event
   is recorded correctly.
 * Since contacts are not being saved there will be issues with
   "following" users and you could overwrite your follower's list with
an empty list.
 * Caching is no longer working.
 * I skipped chat room implementation.
 * Rendering shared event's doesn't work and needs to be revised.
This commit is contained in:
Thomas Mathews 2022-12-15 23:34:41 -08:00
parent e68a022952
commit d02992c7e6
17 changed files with 1383 additions and 1131 deletions

View file

@ -1,7 +1,12 @@
function linkify(text, show_media) {
return text.replace(URL_REGEX, function(match, p1, p2, p3) {
const url = p2+p3
const parsed = new URL(url)
const url = p2+p3;
let parsed;
try {
parsed = new URL(url)
} catch (err) {
return match;
}
let html;
if (show_media && is_img_url(parsed.pathname)) {
html = `
@ -26,10 +31,8 @@ function format_content(ev, show_media) {
return "❤️"
return sanitize(ev.content.trim())
}
const content = ev.content.trim()
const body = convert_quote_blocks(content, show_media)
let cw = get_content_warning(ev.tags)
if (cw !== null) {
let cwHTML = "Content Warning"
@ -38,15 +41,13 @@ function format_content(ev, show_media) {
} else {
cwHTML += `: "<span>${cw}</span>".`
}
const open = !!DAMUS.cw_open[ev.id]? "open" : ""
return `
<details ontoggle="toggle_content_warning(this)" class="cw" id="cw_${ev.id}" ${open}>
<details class="cw">
<summary class="event-message">${cwHTML}</summary>
${body}
</details>
`
}
return body
}
@ -72,3 +73,21 @@ function convert_quote_blocks(content, show_media)
}, "")
}
/* format_profile_name takes in a profile and tries it's best to return a string
* that is best suited for the profile. It also assigns the sanitized_name to
* the profile.
*/
function fmt_profile_name(profile={}, fallback="Anonymous") {
if (profile.sanitized_name)
return profile.sanitized_name
const name = profile.display_name || profile.user || profile.name ||
fallback
profile.sanitized_name = sanitize(name)
return profile.sanitized_name
}
function fmt_pubkey(pk) {
return pk.slice(-8)
}