damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README

commit 917fa903985426e06c884e377da522d05432d47e
parent a024cc558d80fd0ea981328063f4b58c7a8fd022
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  9 Nov 2022 12:50:50 -0800

web: support deletion reasons

When deleting an event, it will now prompt you to type a reason. You can
leave it blank. If you don't, a deletion reason will appear on the
deleted event.

Diffstat:
Mwebv2/damus.js | 40+++++++++++++++++++++++++++-------------
Mwebv2/index.html | 2+-
2 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/webv2/damus.js b/webv2/damus.js @@ -45,7 +45,7 @@ function init_home_model() { events: [], chatrooms: {}, deletions: {}, - deleted: new Set(), + deleted: {}, profiles: {}, profile_events: {}, last_event_of_kind: {}, @@ -194,7 +194,7 @@ function process_deletion_event(model, ev) // we've already recorded this one as a valid deleted event // we can just ignore it - if (model.deleted.has(evid)) + if (model.deleted[evid]) continue let ds = model.deletions[evid] = (model.deletions[evid] || new Set()) @@ -210,8 +210,8 @@ function process_deletion_event(model, ev) function is_deleted(model, evid) { // we've already know it's deleted - if (model.deleted.has(evid)) - return true + if (model.deleted[evid]) + return model.deleted[evid] const ev = model.all_events[evid] if (!ev) @@ -230,7 +230,7 @@ function is_deleted(model, evid) // only allow deletes from the user who created it if (d_ev.pubkey === ev.pubkey) { - model.deleted.add(ev.id) + model.deleted[ev.id] = d_ev log_debug("received deletion for", ev) // clean up deletion data that we don't need anymore delete model.deletions[ev.id] @@ -753,7 +753,12 @@ function delete_post_confirm(evid) { if (!confirm("Are you sure you want to delete this post?")) return - delete_post(evid) + const reason = (prompt("Why you are deleting this? Leave empty to not specify. Type CANCEL to cancel.") || "").trim() + + if (reason.toLowerCase() === "cancel") + return + + delete_post(evid, reason) } function render_unknown_event(model, ev) { @@ -804,10 +809,19 @@ function render_comment_body(model, ev, opts) { ` } -function render_deleted_comment_body() { - return ` - <div class="deleted-comment">This comment was deleted</div> - ` +function render_deleted_comment_body(ev, deleted) { + if (deleted.content) { + const show_media = false + return ` + <div class="deleted-comment"> + This comment was deleted. Reason: + <div class="quote">${format_content(deleted, show_media)}</div> + </div> + ` + } + + + return `<div class="deleted-comment">This comment was deleted</div>` } function render_event(model, ev, opts={}) { @@ -843,7 +857,7 @@ function render_event(model, ev, opts={}) { ${reply_line_bot} </div> <div class="comment-body"> - ${deleted ? render_deleted_comment_body() : render_comment_body(model, ev, opts)} + ${deleted ? render_deleted_comment_body(ev, deleted) : render_comment_body(model, ev, opts)} </div> </div> ` @@ -895,14 +909,14 @@ function render_reaction_group(model, emoji, reactions, reacting_to) { ` } -async function delete_post(id) +async function delete_post(id, reason) { const ev = DSTATE.all_events[id] if (!ev) return const pubkey = await get_pubkey() - let del = await create_deletion_event(pubkey, id) + let del = await create_deletion_event(pubkey, id, reason) console.log("deleting", ev) broadcast_event(del) } diff --git a/webv2/index.html b/webv2/index.html @@ -41,7 +41,7 @@ <script src="noble-secp256k1.js?v=1"></script> <script src="bech32.js?v=1"></script> <script src="nostr.js?v=6"></script> - <script src="damus.js?v=53"></script> + <script src="damus.js?v=54"></script> <script> // I have to delay loading to wait for nos2x const relay = setTimeout(damus_web_init, 100)