Fix reply/root

This commit is contained in:
Jonathan Staab 2023-05-22 17:04:19 -07:00
parent 52bad3ac7b
commit 6ac4df7ee9
3 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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(":"))

View File

@ -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))