fix: don't treat mention-only e tags as replies

Per review: isReply() flagged any e tag as a reply, including one
marked "mention" — a citation, not a thread reply per NIP-10. That
would have hidden quote-notes from the Feed/Profile timelines they
belong in. Also fixed rootReference()'s docstring, which claimed to
fall back to the *last* positional e tag when the code (correctly)
uses the first.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BYiUtZMQeA5RHggQw73wto
This commit is contained in:
2026-09-06 17:55:42 +02:00
parent a4a7ac6e9d
commit 696f64df3f
2 changed files with 24 additions and 2 deletions

View File

@@ -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', () => {

View File

@@ -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", <root-id>], ["e", <reply-id>]`).
*/
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');
}