remove mention tags
This commit is contained in:
@@ -115,32 +115,6 @@ describe("tags", () => {
|
|||||||
expect(e[1][1]).toBe(id)
|
expect(e[1][1]).toBe(id)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle reply to event with root and mention tags", () => {
|
|
||||||
const eventWithRoots = {
|
|
||||||
...mockEvent,
|
|
||||||
tags: [
|
|
||||||
["e", id1, "relay-url"], // deprecated root tag
|
|
||||||
["e", id2, "relay-url"], // deprecated reply type
|
|
||||||
],
|
|
||||||
}
|
|
||||||
const result = tagEventForReply(eventWithRoots)
|
|
||||||
|
|
||||||
const p = result.filter(tag => tag[0] === "p")
|
|
||||||
const e = result.filter(tag => tag[0] === "e")
|
|
||||||
|
|
||||||
// p[0] should be the author of the event
|
|
||||||
expect(p[0][1]).toBe(pubkey)
|
|
||||||
// e[0] should be the root propagated
|
|
||||||
expect(e[0][1]).toBe(id1)
|
|
||||||
expect(e[0][3]).toBe("root")
|
|
||||||
// e[1] should be treated as a mention, it is the note the parent replied to
|
|
||||||
expect(e[1][1]).toBe(id2)
|
|
||||||
expect(e[1][3]).toBe("mention")
|
|
||||||
// e[2] should be the event id and marked as a reply
|
|
||||||
expect(e[2][1]).toBe(id)
|
|
||||||
expect(e[2][3]).toBe("reply")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should handle replaceable events", () => {
|
it("should handle replaceable events", () => {
|
||||||
const replaceableEvent = {
|
const replaceableEvent = {
|
||||||
...mockEvent,
|
...mockEvent,
|
||||||
@@ -161,12 +135,9 @@ describe("tags", () => {
|
|||||||
// e[0] should be the root propagated
|
// e[0] should be the root propagated
|
||||||
expect(e[0][1]).toBe(id1)
|
expect(e[0][1]).toBe(id1)
|
||||||
expect(e[0][3]).toBe("root")
|
expect(e[0][3]).toBe("root")
|
||||||
// e[1] should be treated as a mention, it is the note the parent replied to
|
// e[1] should be the event id and marked as a reply
|
||||||
expect(e[1][1]).toBe(id2)
|
expect(e[1][1]).toBe(id)
|
||||||
expect(e[1][3]).toBe("mention")
|
expect(e[1][3]).toBe("reply")
|
||||||
// e[2] should be the event id and marked as a reply
|
|
||||||
expect(e[2][1]).toBe(id)
|
|
||||||
expect(e[2][3]).toBe("reply")
|
|
||||||
|
|
||||||
// a[0] should be the address of the replaceable event
|
// a[0] should be the address of the replaceable event
|
||||||
expect(a[0][1]).toBe(getAddress(replaceableEvent))
|
expect(a[0][1]).toBe(getAddress(replaceableEvent))
|
||||||
|
|||||||
+14
-34
@@ -1,10 +1,11 @@
|
|||||||
import {uniq, remove, nthEq} from "@welshman/lib"
|
import {uniq, remove} from "@welshman/lib"
|
||||||
import {
|
import {
|
||||||
getAddress,
|
getAddress,
|
||||||
isReplaceable,
|
isReplaceable,
|
||||||
getReplyTags,
|
getReplyTags,
|
||||||
getPubkeyTagValues,
|
getPubkeyTagValues,
|
||||||
isReplaceableKind,
|
isReplaceableKind,
|
||||||
|
isShareableRelayUrl,
|
||||||
} from "@welshman/util"
|
} from "@welshman/util"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {Router} from "@welshman/router"
|
import {Router} from "@welshman/router"
|
||||||
@@ -48,41 +49,20 @@ export const tagEventForQuote = (event: TrustedEvent) => [
|
|||||||
|
|
||||||
export const tagEventForReply = (event: TrustedEvent) => {
|
export const tagEventForReply = (event: TrustedEvent) => {
|
||||||
const tags = tagEventPubkeys(event)
|
const tags = tagEventPubkeys(event)
|
||||||
|
const {roots, replies} = getReplyTags(event.tags)
|
||||||
// Based on NIP 10 legacy tags, order is root, mentions, reply
|
const parents = roots.length > 0 ? roots : replies
|
||||||
const {roots, replies, mentions} = getReplyTags(event.tags)
|
const mark = parents.length > 0 ? "reply" : "root"
|
||||||
|
|
||||||
// Root comes first
|
|
||||||
if (roots.length > 0) {
|
|
||||||
for (const t of roots) {
|
|
||||||
tags.push([...t.slice(0, 2), Router.get().EventRoots(event).getUrl() || "", "root"])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const t of replies) {
|
|
||||||
tags.push([...t.slice(0, 2), Router.get().EventParents(event).getUrl() || "", "root"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inherit mentions
|
|
||||||
for (const t of mentions) {
|
|
||||||
if (!tags.some(nthEq(1, t[1]))) {
|
|
||||||
tags.push([...t.slice(0, 3), "mention"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inherit replies if they weren't already included
|
|
||||||
if (roots.length > 0) {
|
|
||||||
for (const t of replies) {
|
|
||||||
if (!tags.some(nthEq(1, t[1]))) {
|
|
||||||
tags.push([...t.slice(0, 3), "mention"])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, tag the event itself
|
|
||||||
const mark = replies.length > 0 ? "reply" : "root"
|
|
||||||
const hint = Router.get().Event(event).getUrl() || ""
|
const hint = Router.get().Event(event).getUrl() || ""
|
||||||
|
|
||||||
|
// If the parent included roots use them, otherwise use replies as a fallback
|
||||||
|
for (const [k, id, originalHint = "", _, pubkey = ""] of parents) {
|
||||||
|
const hint = isShareableRelayUrl(originalHint)
|
||||||
|
? originalHint
|
||||||
|
: Router.get().EventRoots(event).getUrl()
|
||||||
|
|
||||||
|
tags.push([k, id, hint || "", "root", pubkey])
|
||||||
|
}
|
||||||
|
|
||||||
// e-tag the event
|
// e-tag the event
|
||||||
tags.push(["e", event.id, hint, mark, event.pubkey])
|
tags.push(["e", event.id, hint, mark, event.pubkey])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user