diff --git a/src/lib/nostrUtils.test.ts b/src/lib/nostrUtils.test.ts index b18c721..afe93c8 100644 --- a/src/lib/nostrUtils.test.ts +++ b/src/lib/nostrUtils.test.ts @@ -26,6 +26,21 @@ describe('isReply', () => { it('is true for a note using the deprecated positional e tag', () => { expect(isReply(note([['e', 'parent-id']]))).toBe(true); }); + + it('is false for a note that only mentions another event', () => { + expect(isReply(note([['e', 'mentioned-id', '', 'mention']]))).toBe(false); + }); + + it('is true for a note with a mention alongside a marked reply', () => { + expect( + isReply( + note([ + ['e', 'root-id', '', 'root'], + ['e', 'mentioned-id', '', 'mention'], + ]), + ), + ).toBe(true); + }); }); describe('rootReference', () => { diff --git a/src/lib/nostrUtils.ts b/src/lib/nostrUtils.ts index 7b1247d..7477925 100644 --- a/src/lib/nostrUtils.ts +++ b/src/lib/nostrUtils.ts @@ -93,7 +93,8 @@ export function tagValues(event: NostrEvent, name: string): string[] { /** * The event a reply points at, following NIP-10: prefer an explicit `root` - * marker, fall back to the last positional `e` tag. + * marker, fall back to the first positional `e` tag (the deprecated scheme + * puts the root id first: `["e", ], ["e", ]`). */ export function rootReference(event: NostrEvent): string | undefined { const marked = event.tags.find(([name, , , marker]) => name === 'e' && marker === 'root'); @@ -102,6 +103,12 @@ export function rootReference(event: NostrEvent): string | undefined { return positional[0]?.[1]; } +/** + * True for a reply per NIP-10: a marked `root`/`reply` `e` tag, or an + * unmarked one (the deprecated positional scheme). An `e` tag marked + * `mention` alone does not make an event a reply — it cites another event + * without being part of its thread. + */ export function isReply(event: NostrEvent): boolean { - return event.tags.some(([name]) => name === 'e'); + return event.tags.some(([name, , , marker]) => name === 'e' && marker !== 'mention'); }