damus.io

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

commit 5f5cbbd80a325c353e11805620aa808d803002a9
parent 9be8194dace1f8236713cf602afe91e290fd5f41
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  4 Nov 2022 15:09:07 -0700

web: don't show media when replying

it's too big

Diffstat:
Mwebv2/damus.js | 20+++++++++++---------
Mwebv2/index.html | 2+-
2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/webv2/damus.js b/webv2/damus.js @@ -644,6 +644,8 @@ function render_event(model, ev, opts={}) { const replied_events = render_replied_events(model, ev, opts) const reply_line_top = replied_events === "" ? "" : render_reply_line_top() + const show_media = !opts.is_composing + return ` ${replied_events} <div id="ev${ev.id}" class="comment"> @@ -659,7 +661,7 @@ function render_event(model, ev, opts={}) { <div class="comment-body"> ${render_replying_to(model, ev)} <p> - ${format_content(ev)} + ${format_content(ev, show_media)} </p> ${render_reactions(model, ev)} ${bar} @@ -961,12 +963,12 @@ function is_video_url(path) { } const URL_REGEX = /(https?:\/\/[^\s\):]+)/g; -function linkify(text) { +function linkify(text, show_media) { return text.replace(URL_REGEX, function(url) { const parsed = new URL(url) - if (is_img_url(parsed.pathname)) + if (show_media && is_img_url(parsed.pathname)) return `<img class="inline-img" src="${url}"/>`; - else if (is_video_url(parsed.pathname)) + else if (show_media && is_video_url(parsed.pathname)) return ` <video controls class="inline-img" /> <source src="${url}"> @@ -977,7 +979,7 @@ function linkify(text) { }) } -function convert_quote_blocks(content) +function convert_quote_blocks(content, show_media) { const split = content.split("\n") let blockin = false @@ -987,19 +989,19 @@ function convert_quote_blocks(content) str += "<span class='quote'>" blockin = true } - str += linkify(sanitize(line.slice(1))) + str += linkify(sanitize(line.slice(1)), show_media) } else { if (blockin) { blockin = false str += "</span>" } - str += linkify(sanitize(line)) + str += linkify(sanitize(line), show_media) } return str + "<br/>" }, "") } -function format_content(ev) +function format_content(ev, show_media) { if (ev.kind === 7) { if (ev.content === "" || ev.content === "+") @@ -1007,7 +1009,7 @@ function format_content(ev) return sanitize(ev.content) } - return convert_quote_blocks(ev.content) + return convert_quote_blocks(ev.content, show_media) } function sanitize(content) 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=46"></script> + <script src="damus.js?v=47"></script> <script> // I have to delay loading to wait for nos2x const relay = setTimeout(damus_web_init, 100)