web: support content warnings
This commit is contained in:
parent
917fa90398
commit
17d4f9e468
3 changed files with 61 additions and 3 deletions
|
@ -83,6 +83,17 @@ body {
|
||||||
background: rgba(0,0,0,0.4);
|
background: rgba(0,0,0,0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
details {
|
||||||
|
background-color: rgba(255,255,255,0.2);
|
||||||
|
padding: 10px;
|
||||||
|
margin-right: 30px;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
textarea, input {
|
textarea, input {
|
||||||
background-color: rgba(255,255,255,0.2);
|
background-color: rgba(255,255,255,0.2);
|
||||||
border: 0;
|
border: 0;
|
||||||
|
|
|
@ -45,6 +45,7 @@ function init_home_model() {
|
||||||
events: [],
|
events: [],
|
||||||
chatrooms: {},
|
chatrooms: {},
|
||||||
deletions: {},
|
deletions: {},
|
||||||
|
cw_open: {},
|
||||||
deleted: {},
|
deleted: {},
|
||||||
profiles: {},
|
profiles: {},
|
||||||
profile_events: {},
|
profile_events: {},
|
||||||
|
@ -533,6 +534,13 @@ function redraw_events(model) {
|
||||||
//log_debug("rendering home view")
|
//log_debug("rendering home view")
|
||||||
model.rendered = {}
|
model.rendered = {}
|
||||||
model.events_el.innerHTML = render_events(model)
|
model.events_el.innerHTML = render_events(model)
|
||||||
|
setup_home_event_handlers(model.events_el)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup_home_event_handlers(events_el)
|
||||||
|
{
|
||||||
|
for (const el of events_el.querySelectorAll(".cw"))
|
||||||
|
el.addEventListener("toggle", toggle_content_warning.bind(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
function redraw_home_view(model) {
|
function redraw_home_view(model) {
|
||||||
|
@ -1222,6 +1230,30 @@ function convert_quote_blocks(content, show_media)
|
||||||
}, "")
|
}, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_content_warning(tags)
|
||||||
|
{
|
||||||
|
for (const tag of tags) {
|
||||||
|
if (tag.length >= 1 && tag[0] === "content-warning")
|
||||||
|
return tag[1] || ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggle_content_warning(e)
|
||||||
|
{
|
||||||
|
const el = e.target
|
||||||
|
const id = el.id.split("_")[1]
|
||||||
|
const ev = DSTATE.all_events[id]
|
||||||
|
|
||||||
|
if (!ev) {
|
||||||
|
log_debug("could not find content-warning event", id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
DSTATE.cw_open[id] = el.open
|
||||||
|
}
|
||||||
|
|
||||||
function format_content(ev, show_media)
|
function format_content(ev, show_media)
|
||||||
{
|
{
|
||||||
if (ev.kind === 7) {
|
if (ev.kind === 7) {
|
||||||
|
@ -1230,7 +1262,22 @@ function format_content(ev, show_media)
|
||||||
return sanitize(ev.content.trim())
|
return sanitize(ev.content.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
return convert_quote_blocks(ev.content.trim(), show_media)
|
const content = ev.content.trim()
|
||||||
|
const body = convert_quote_blocks(content, show_media)
|
||||||
|
|
||||||
|
let cw = get_content_warning(ev.tags)
|
||||||
|
if (cw !== null) {
|
||||||
|
cw = cw === ""? "Content Warning" : `Content Warning: ${cw}`
|
||||||
|
const open = !!DSTATE.cw_open[ev.id]? "open" : ""
|
||||||
|
return `
|
||||||
|
<details class="cw" id="cw_${ev.id}" ${open}>
|
||||||
|
<summary>${cw}</summary>
|
||||||
|
${body}
|
||||||
|
</details>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitize(content)
|
function sanitize(content)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<title>Damus</title>
|
<title>Damus</title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="damus.css?v=17">
|
<link rel="stylesheet" href="damus.css?v=18">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<section class="header">
|
<section class="header">
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
<script src="noble-secp256k1.js?v=1"></script>
|
<script src="noble-secp256k1.js?v=1"></script>
|
||||||
<script src="bech32.js?v=1"></script>
|
<script src="bech32.js?v=1"></script>
|
||||||
<script src="nostr.js?v=6"></script>
|
<script src="nostr.js?v=6"></script>
|
||||||
<script src="damus.js?v=54"></script>
|
<script src="damus.js?v=55"></script>
|
||||||
<script>
|
<script>
|
||||||
// I have to delay loading to wait for nos2x
|
// I have to delay loading to wait for nos2x
|
||||||
const relay = setTimeout(damus_web_init, 100)
|
const relay = setTimeout(damus_web_init, 100)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue