(tags: string[][])
| 23 | } |
| 24 | |
| 25 | export function getThreadReference(tags: string[][]): ThreadReference { |
| 26 | const eventTags = getEventTags(tags); |
| 27 | |
| 28 | if (eventTags.length === 0) { |
| 29 | return { |
| 30 | parentId: null, |
| 31 | rootId: null, |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | const rootTag = eventTags.find((tag) => tag[3] === "root"); |
| 36 | const replyTag = |
| 37 | [...eventTags].reverse().find((tag) => tag[3] === "reply") ?? null; |
| 38 | |
| 39 | if (!replyTag) { |
| 40 | return { |
| 41 | parentId: null, |
| 42 | rootId: null, |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | const parentId = replyTag[1] ?? null; |
| 47 | |
| 48 | return { |
| 49 | parentId, |
| 50 | rootId: rootTag?.[1] ?? parentId, |
| 51 | }; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Best-effort client-side normalization of mention pubkeys: lowercase, deduplicate, skip self. |
no test coverage detected