mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-19 11:43:35 +00:00
Fix tag inheritance for replies
This commit is contained in:
parent
0f9db6c5fb
commit
e74296d767
@ -38,6 +38,8 @@
|
|||||||
|
|
||||||
# More
|
# More
|
||||||
|
|
||||||
|
- [ ] Add delete button to notes. This will require tracking what relays a note was published to
|
||||||
|
- [ ] Add image proxy to avoid leaking user ips to hosts
|
||||||
- [ ] Show an error when something fails to load with a constructive suggestion
|
- [ ] Show an error when something fails to load with a constructive suggestion
|
||||||
- [ ] Show more link on long notes (rather than just an ellipsis)
|
- [ ] Show more link on long notes (rather than just an ellipsis)
|
||||||
- [ ] Log in as user button
|
- [ ] Log in as user button
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {pick, prop, join, uniqBy, last} from 'ramda'
|
import {pick, last, prop, uniqBy} from 'ramda'
|
||||||
import {get} from 'svelte/store'
|
import {get} from 'svelte/store'
|
||||||
import {roomAttrs, displayPerson, findReplyId, findRootId} from 'src/util/nostr'
|
import {roomAttrs, displayPerson, findReplyId, findRootId} from 'src/util/nostr'
|
||||||
import {getPubkeyWriteRelays, getRelayForPersonHint, sampleRelays} from 'src/agent/relays'
|
import {getPubkeyWriteRelays, getRelayForPersonHint, sampleRelays} from 'src/agent/relays'
|
||||||
@ -54,34 +54,47 @@ const createNote = (content, mentions = [], topics = []) => {
|
|||||||
return new PublishableEvent(1, {content, tags: mentions.concat(topics)})
|
return new PublishableEvent(1, {content, tags: mentions.concat(topics)})
|
||||||
}
|
}
|
||||||
|
|
||||||
const createReaction = (note, content) => {
|
const getReplyTags = n => {
|
||||||
const {url} = getRelayForPersonHint(note.pubkey, note)
|
const {url} = getRelayForPersonHint(n.pubkey, n)
|
||||||
const tags = uniqBy(
|
const rootId = findRootId(n) || findReplyId(n) || n.id
|
||||||
join(':'),
|
|
||||||
note.tags
|
|
||||||
.filter(t => ["p", "e"].includes(t[0]))
|
|
||||||
.map(t => last(t) === 'reply' ? t.slice(0, -1) : t)
|
|
||||||
.concat([["p", note.pubkey, url], ["e", note.id, url, 'reply']])
|
|
||||||
)
|
|
||||||
|
|
||||||
return new PublishableEvent(7, {content, tags})
|
return [["p", n.pubkey, url], ["e", n.id, url, 'reply'], ["e", rootId, url, 'root']]
|
||||||
}
|
}
|
||||||
|
|
||||||
const createReply = (note, content, mentions = [], topics = []) => {
|
const tagsFromParent = (n, newTags = []) => {
|
||||||
const {url} = getRelayForPersonHint(note.pubkey, note)
|
const pubkey = get(keys.pubkey)
|
||||||
const rootId = findRootId(note) || findReplyId(note) || note.id
|
|
||||||
|
|
||||||
|
return uniqBy(
|
||||||
|
// Remove duplicates due to inheritance. Keep earlier ones
|
||||||
|
t => t.slice(0, 2).join(':'),
|
||||||
|
// Mentions have to come first for interpolation to work
|
||||||
|
newTags
|
||||||
|
// Add standard reply tags
|
||||||
|
.concat(getReplyTags(n))
|
||||||
|
// Inherit p and e tags, but remove marks and self-mentions
|
||||||
|
.concat(
|
||||||
|
n.tags
|
||||||
|
.filter(t => {
|
||||||
|
if (t[1] === pubkey) return false
|
||||||
|
if (!["p", "e"].includes(t[0])) return false
|
||||||
|
if (['reply', 'root'].includes(last(t))) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const createReaction = (note, content) =>
|
||||||
|
new PublishableEvent(7, {content, tags: getReplyTags(note)})
|
||||||
|
|
||||||
|
const createReply = (note, content, mentions = [], topics = []) => {
|
||||||
// Mentions have to come first so interpolation works
|
// Mentions have to come first so interpolation works
|
||||||
const tags = uniqBy(
|
const tags = tagsFromParent(
|
||||||
join(':'),
|
note,
|
||||||
mentions
|
mentions
|
||||||
.map(pk => ["p", pk, prop('url', getRelayForPersonHint(pk, note))])
|
.map(pk => ["p", pk, prop('url', getRelayForPersonHint(pk, note))])
|
||||||
.concat(topics.map(t => ["t", t]))
|
.concat(topics.map(t => ["t", t]))
|
||||||
.concat([
|
|
||||||
["p", note.pubkey, url],
|
|
||||||
["e", note.id, url, 'reply'],
|
|
||||||
["e", rootId, url, 'root'],
|
|
||||||
])
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return new PublishableEvent(1, {content, tags})
|
return new PublishableEvent(1, {content, tags})
|
||||||
|
Loading…
Reference in New Issue
Block a user