From 6ac4df7ee932fe04276873b1d49aa1532624628b Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Mon, 22 May 2023 17:04:19 -0700 Subject: [PATCH] Fix reply/root --- ROADMAP.md | 1 + src/agent/cmd.ts | 12 +++++++++--- src/util/nostr.ts | 8 ++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 6d37bcf2..8dfb7ecf 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,6 +1,7 @@ # Current - [ ] Add threads - replies by self get shown at the top of replies? +- [ ] Fix rich text -> plain text using library - [ ] Highlights - Allow highlighting text in notes - When something is highlighted, show fixed-position elements for adding highlights diff --git a/src/agent/cmd.ts b/src/agent/cmd.ts index b55cfc25..6fae9103 100644 --- a/src/agent/cmd.ts +++ b/src/agent/cmd.ts @@ -76,7 +76,7 @@ const createReply = (note, content, mentions = [], topics = []) => { [ tags => tags.concat(processMentions(mentions)), tags => tags.concat(topics.map(t => ["t", t])), - tags => tags.concat(getReplyTags(note)), + tags => tags.concat(getReplyTags(note, true)), tags => tagsFromContent(content, tags), uniqTags, ] @@ -132,7 +132,13 @@ const tagsFromContent = (content, tags) => { return tags } -const getReplyTags = n => { +const getReplyTags = (n, inherit = false) => { + const extra = inherit + ? Tags.from(n) + .type("e") + .all() + .map(t => t.slice(0, 3)) + : [] const pHint = getRelayForPersonHint(n.pubkey) const eHint = getRelayForEventHint(n) || pHint const reply = ["e", n.id, eHint?.url || "", "reply"] @@ -141,7 +147,7 @@ const getReplyTags = n => { t => t.slice(0, 3).concat("root"), ]) - return [["p", n.pubkey, pHint?.url || ""], root, reply] + return [["p", n.pubkey, pHint?.url || ""], root, ...extra, reply] } const uniqTags = uniqBy(t => t.slice(0, 2).join(":")) diff --git a/src/util/nostr.ts b/src/util/nostr.ts index f8e4a1b6..9035d286 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -88,10 +88,10 @@ export const findReplyAndRoot = e => { return {reply, root} } - return { - reply: tags.mark("reply").first(), - root: tags.mark("root").first(), - } + const reply = tags.mark("reply").first() + const root = tags.mark("root").first() + + return {reply: reply || root, root} } export const findReply = e => prop("reply", findReplyAndRoot(e))