diff --git a/packages/app/__tests__/tags.test.ts b/packages/app/__tests__/tags.test.ts index a3e4209..406c4a9 100644 --- a/packages/app/__tests__/tags.test.ts +++ b/packages/app/__tests__/tags.test.ts @@ -115,32 +115,6 @@ describe("tags", () => { 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", () => { const replaceableEvent = { ...mockEvent, @@ -161,12 +135,9 @@ describe("tags", () => { // 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") + // e[1] should be the event id and marked as a reply + expect(e[1][1]).toBe(id) + expect(e[1][3]).toBe("reply") // a[0] should be the address of the replaceable event expect(a[0][1]).toBe(getAddress(replaceableEvent)) diff --git a/packages/app/src/tags.ts b/packages/app/src/tags.ts index ab9e7bc..dab9beb 100644 --- a/packages/app/src/tags.ts +++ b/packages/app/src/tags.ts @@ -1,10 +1,11 @@ -import {uniq, remove, nthEq} from "@welshman/lib" +import {uniq, remove} from "@welshman/lib" import { getAddress, isReplaceable, getReplyTags, getPubkeyTagValues, isReplaceableKind, + isShareableRelayUrl, } from "@welshman/util" import type {TrustedEvent} from "@welshman/util" import {Router} from "@welshman/router" @@ -48,41 +49,20 @@ export const tagEventForQuote = (event: TrustedEvent) => [ export const tagEventForReply = (event: TrustedEvent) => { const tags = tagEventPubkeys(event) - - // Based on NIP 10 legacy tags, order is root, mentions, reply - const {roots, replies, mentions} = getReplyTags(event.tags) - - // 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 {roots, replies} = getReplyTags(event.tags) + const parents = roots.length > 0 ? roots : replies + const mark = parents.length > 0 ? "reply" : "root" 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 tags.push(["e", event.id, hint, mark, event.pubkey])