diff --git a/js/core.js b/js/core.js index 3d6a498..4d71ae6 100644 --- a/js/core.js +++ b/js/core.js @@ -61,6 +61,24 @@ function broadcast_event(ev) { DAMUS.pool.send(["EVENT", ev]) } +async function share(evid) { + const model = DAMUS; + const e = model.all_events[evid]; + if (!e) + return; + let ev = { + kind: KIND_SHARE, + created_at: new_creation_time(), + pubkey: model.pubkey, + content: JSON.stringify(e), + tags: [["e", e.id], ["p", e.pubkey]], + } + ev.id = await nostrjs.calculate_id(ev); + ev = await sign_event(ev); + broadcast_event(ev); + return ev; +} + async function update_profile(profile={}) { let ev = { kind: KIND_METADATA, diff --git a/js/event.js b/js/event.js index 856a24a..864d447 100644 --- a/js/event.js +++ b/js/event.js @@ -37,7 +37,7 @@ function event_calculate_pow(ev) { * event in the manner of a chat. */ function event_can_reply(ev) { - return ev.kind === KIND_NOTE || ev.kind === 42 + return ev.kind === KIND_NOTE; // || ev.kind === KIND_CHATROOM; } /* event_is_timeline returns a boolean based on if the event should be rendered diff --git a/js/main.js b/js/main.js index c7e629f..debe539 100644 --- a/js/main.js +++ b/js/main.js @@ -134,7 +134,6 @@ function on_timer_save() { const model = DAMUS; model_save_events(model); model_save_settings(model); - contacts_save(model.contacts); on_timer_save(); }, 10 * 1000); } diff --git a/js/model.js b/js/model.js index a84d9f1..759198d 100644 --- a/js/model.js +++ b/js/model.js @@ -291,7 +291,7 @@ async function model_save_settings(model) { tx.oncomplete = (ev) => { db.close(); resolve(); - log_debug("settings saved"); + //log_debug("settings saved"); }; tx.onerror = (ev) => { db.close(); @@ -340,7 +340,7 @@ async function model_save_events(model) { tx.oncomplete = (ev) => { db.close(); resolve(); - log_debug("saved events!"); + //log_debug("saved events!"); }; tx.onerror = (ev) => { db.close(); diff --git a/js/ui/render.js b/js/ui/render.js index 7e3380a..6805788 100644 --- a/js/ui/render.js +++ b/js/ui/render.js @@ -24,7 +24,7 @@ function render_replying_to(model, ev) { ` } -function render_share(damus, view, ev, opts) { +function render_share(damus, 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. @@ -32,30 +32,13 @@ function render_share(damus, view, ev, opts) { return ""; opts.shared = { pubkey: ev.pubkey, - profile: damus.profiles[ev.pubkey] + profile: damus.profiles[ev.pubkey], + share_time: ev.created_at, + share_evid: ev.id, } 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 ""; @@ -65,12 +48,6 @@ function render_shared_by(ev, opts) { } 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); } @@ -78,13 +55,11 @@ function render_event(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"; + const border_bottom = opts.is_composing ? "" : "bottom-border"; let thread_btn = ""; - if (!reply_line_bot) reply_line_bot = ''; return html`+ ${format_content(ev, show_media)} +
`; + str += render_reactions(model, ev); + str += opts.nobar ? "" : + render_action_bar(model, ev, {can_delete, shared}); + return str; +} + function render_react_onclick(our_pubkey, reacting_to, emoji, reactions) { const reaction = reactions[our_pubkey] if (!reaction) { @@ -154,22 +147,14 @@ function render_reaction_group(model, emoji, reactions, reacting_to) { function render_action_bar(model, ev, opts={}) { const { pubkey } = model; - let { can_delete } = opts; - let delete_html = "" - if (can_delete) { - delete_html = html` - ` - } - + let { can_delete, shared } = opts; // TODO rewrite all of the toggle heart code. It's mine & I hate it. const reaction = model_get_reacts_to(model, pubkey, ev.id, R_HEART); const liked = !!reaction; const reaction_id = reaction ? reaction.id : ""; - return html` - "; } function render_reactions_inner(model, ev) { diff --git a/js/ui/state.js b/js/ui/state.js index d134277..6d80748 100644 --- a/js/ui/state.js +++ b/js/ui/state.js @@ -223,6 +223,7 @@ function view_render_event(model, ev, force=false) { return model.elements[ev.id]; const html = render_event(model, ev, {}); if (html == "") { + //log_debug(`failed to render ${ev.id}`); return; } const div = document.createElement("div"); @@ -244,7 +245,10 @@ function view_timeline_update_profiles(model, ev) { continue; const el = model.elements[evid]; find_node(`.username[data-pubkey='${pk}']`, el).innerText = name; - find_node(`img.pfp[data-pubkey='${pk}']`, el).src = pic; + // TODO Sometimes this fails and I don't know why + let img = find_node(`img.pfp[data-pubkey='${pk}']`, el); + if (img) + img.src = pic; } // Update the profile view if it's active if (el.dataset.mode == VM_USER && el.dataset.pubkey == pk) { @@ -302,6 +306,7 @@ function view_mode_contains_event(model, ev, mode, opts={}) { case VM_FRIENDS: return ev.pubkey == model.pubkey || contact_is_friend(model.contacts, ev.pubkey); case VM_THREAD: + if (ev.kind == KIND_SHARE) return false; return ev.id == opts.thread_id || (ev.refs && ( ev.refs.root == opts.thread_id || ev.refs.reply == opts.thread_id)); diff --git a/js/ui/util.js b/js/ui/util.js index e260dd9..7948b81 100644 --- a/js/ui/util.js +++ b/js/ui/util.js @@ -127,12 +127,8 @@ function show_new() { view_timeline_show_new(DAMUS); } -/* click_event opens the thread view from the element's specified element id - * "dataset.eid". - */ -function click_event(el) { - console.info(`thread to open: ${el.dataset.eid}`); - switch_view("thread"); +function click_share(el) { + share(el.dataset.evid); } function click_toggle_like(el) {