Added reply one/all because it was annoying me
This commit is contained in:
parent
7ce72540cf
commit
646a0a2daf
3 changed files with 37 additions and 14 deletions
32
js/core.js
32
js/core.js
|
@ -129,30 +129,40 @@ async function send_post() {
|
|||
post_input_changed(input_el)
|
||||
}
|
||||
|
||||
function new_reply_tags(ev) {
|
||||
return [
|
||||
["e", ev.id, "", "reply"],
|
||||
["p", ev.pubkey],
|
||||
];
|
||||
}
|
||||
|
||||
async function create_reply(pubkey, content, from) {
|
||||
const tags = gather_reply_tags(pubkey, from)
|
||||
const created_at = Math.floor(new Date().getTime() / 1000)
|
||||
let kind = from.kind
|
||||
async function create_reply(pubkey, content, ev, all=true) {
|
||||
const tags = all ? gather_reply_tags(pubkey, ev) : new_reply_tags(ev);
|
||||
const created_at = new_creation_time();
|
||||
let kind = ev.kind;
|
||||
|
||||
// convert emoji replies into reactions
|
||||
if (is_valid_reaction_content(content))
|
||||
kind = 7
|
||||
|
||||
let reply = { pubkey, tags, content, created_at, kind }
|
||||
|
||||
kind = 7;
|
||||
let reply = {
|
||||
pubkey,
|
||||
tags,
|
||||
content,
|
||||
created_at,
|
||||
kind
|
||||
}
|
||||
reply.id = await nostrjs.calculate_id(reply)
|
||||
reply = await sign_event(reply)
|
||||
return reply
|
||||
}
|
||||
|
||||
async function send_reply(content, replying_to) {
|
||||
async function send_reply(content, replying_to, all=true) {
|
||||
const ev = DAMUS.all_events[replying_to]
|
||||
if (!ev)
|
||||
return
|
||||
return;
|
||||
|
||||
const pubkey = await get_pubkey()
|
||||
let reply = await create_reply(pubkey, content, ev)
|
||||
let reply = await create_reply(pubkey, content, ev, all)
|
||||
|
||||
broadcast_event(reply)
|
||||
broadcast_related_events(reply)
|
||||
|
|
|
@ -226,9 +226,12 @@ function render_action_bar(model, ev, opts={}) {
|
|||
const reaction_id = reaction ? reaction.id : "";
|
||||
return html`
|
||||
<div class="action-bar">
|
||||
<button class="icon" title="Reply" onclick="reply_to('${ev.id}')">
|
||||
<button class="icon" title="Reply" onclick="reply_author('${ev.id}')">
|
||||
<img class="icon svg small" src="icon/event-reply.svg"/>
|
||||
</button>
|
||||
<button class="icon" title="Reply All" onclick="reply_all('${ev.id}')">
|
||||
<img class="icon svg small" src="icon/event-reply-all.svg"/>
|
||||
</button>
|
||||
<button class="icon react heart ${ab(liked, 'liked', '')}"
|
||||
onclick="click_toggle_like(this)"
|
||||
data-reaction-id="${reaction_id}"
|
||||
|
|
|
@ -187,19 +187,21 @@ async function do_send_reply() {
|
|||
const modal = document.querySelector("#reply-modal");
|
||||
const replying_to = modal.querySelector("#replying-to");
|
||||
const evid = replying_to.dataset.evid;
|
||||
const all = replying_to.dataset.toAll != "";
|
||||
const reply_content_el = document.querySelector("#reply-content");
|
||||
const content = reply_content_el.value;
|
||||
await send_reply(content, evid);
|
||||
await send_reply(content, evid, all);
|
||||
reply_content_el.value = "";
|
||||
close_reply();
|
||||
}
|
||||
|
||||
function reply_to(evid) {
|
||||
function reply(evid, all=false) {
|
||||
const ev = DAMUS.all_events[evid]
|
||||
const modal = document.querySelector("#reply-modal")
|
||||
const replybox = modal.querySelector("#reply-content")
|
||||
const replying_to = modal.querySelector("#replying-to")
|
||||
replying_to.dataset.evid = evid
|
||||
replying_to.dataset.toAll = all ? "all" : "";
|
||||
replying_to.innerHTML = render_event_nointeract(DAMUS, ev, {
|
||||
is_composing: true,
|
||||
nobar: true
|
||||
|
@ -208,6 +210,14 @@ function reply_to(evid) {
|
|||
replybox.focus()
|
||||
}
|
||||
|
||||
function reply_author(evid) {
|
||||
reply(evid);
|
||||
}
|
||||
|
||||
function reply_all(evid) {
|
||||
reply(evid, true);
|
||||
}
|
||||
|
||||
function redraw_my_pfp(model) {
|
||||
const p = model.profiles[model.pubkey]
|
||||
const html = render_pfp(model.pubkey, p || {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue