// This file contains all methods related to rendering UI elements. Rendering // is done by simple string manipulations & templates. If you need to write // loops simply write it in code and return strings. function render_replying_to(model, ev) { if (!(ev.refs && ev.refs.reply)) return ""; if (ev.kind === KIND_CHATROOM) return render_replying_to_chat(model, ev); let pubkeys = ev.refs.pubkeys || [] if (pubkeys.length === 0 && ev.refs.reply) { const replying_to = model.all_events[ev.refs.reply] if (!replying_to) return html`
`; pubkeys = [replying_to.pubkey] } const names = pubkeys.map((pk) => { return render_mentioned_name(pk, model.profiles[pk]); }).join(", ") return ` ` } function render_share(damus, view, ev, opts) { const shared_ev = damus.all_events[ev.refs && ev.refs.root] // If the shared event hasn't been resolved or leads to a circular event // kind we will skip out on it. if (!shared_ev || shared_ev.kind == KIND_SHARE) return ""; opts.shared = { pubkey: ev.pubkey, profile: damus.profiles[ev.pubkey] } return render_event(damus, shared_ev, opts) } function render_comment_body(model, ev, opts) { const can_delete = model.pubkey === ev.pubkey; const bar = !event_can_reply(ev) || opts.nobar ? "" : render_action_bar(model, ev, {can_delete}); // Only show media for content that is by friends. const show_media = !opts.is_composing && model.contacts.friends.has(ev.pubkey); return `${format_content(ev, show_media)}
${render_reactions(model, ev)} ${bar}` } function render_shared_by(ev, opts) { if (!opts.shared) return ""; const { profile, pubkey } = opts.shared return ` ` } function render_event(model, ev, opts={}) { let { has_bot_line, has_top_line, reply_line_bot, } = opts if (ev.kind == KIND_SHARE) { return render_share(model, ev, opts); } const thread_root = (ev.refs && ev.refs.root) || ev.id; const profile = model.profiles[ev.pubkey]; const delta = fmt_since_str(new Date().getTime(), ev.created_at*1000) const border_bottom = opts.is_composing || has_bot_line ? "" : "bottom-border"; let thread_btn = ""; if (!reply_line_bot) reply_line_bot = ''; return html`