diff --git a/src/app/components/CommentTree.svelte b/src/app/components/CommentTree.svelte index 13c6408f..eb63fbca 100644 --- a/src/app/components/CommentTree.svelte +++ b/src/app/components/CommentTree.svelte @@ -21,18 +21,19 @@ node: CommentNode root: TrustedEvent replyTo?: TrustedEvent - setReplyTo: (comment?: TrustedEvent) => void + setReplyTo?: (comment?: TrustedEvent) => void url?: string context: FeedContext + maxDepth?: number } - const {node, root, replyTo, setReplyTo, url, context}: Props = $props() + const {node, root, replyTo, setReplyTo, url, context, maxDepth = Infinity}: Props = $props() const composing = $derived(replyTo?.id === node.comment.id) - const reply = () => setReplyTo(node.comment) + const reply = () => setReplyTo?.(node.comment) - const clearReplyTo = () => setReplyTo(undefined) + const clearReplyTo = () => setReplyTo?.(undefined) const openProfile = () => pushModal(ProfileDetail, {pubkey: node.comment.pubkey, url}) @@ -70,11 +71,13 @@ {#if url} -
- +
+ {#if setReplyTo} + + {/if}
{/if} @@ -91,14 +94,21 @@ onSubmit={clearReplyTo} />
{/if} - {#if node.children.length > 0} + {#if node.children.length > 0 && maxDepth > 1}
{#each node.children as child (child.comment.id)} - + {/each}
{/if} diff --git a/src/app/components/HomeNetwork.svelte b/src/app/components/HomeNetwork.svelte index 6ac0466a..9c8ef6ea 100644 --- a/src/app/components/HomeNetwork.svelte +++ b/src/app/components/HomeNetwork.svelte @@ -12,7 +12,7 @@ import Masonry from "@lib/components/Masonry.svelte" import Spinner from "@lib/components/Spinner.svelte" import HomeSection from "@app/components/HomeSection.svelte" - import NoteItem from "@app/components/NoteItem.svelte" + import HomeNetworkItem from "@app/components/HomeNetworkItem.svelte" import {followLists, relayLists, router, user} from "@app/core" import {isFeedLoading, makeFeed, makeFeedContext, makeScrollLoader} from "@app/feeds" @@ -20,7 +20,10 @@ // `syncFollowNetwork` reads their lists from. const RELAY_LIMIT = 8 - const context = makeFeedContext({relays: $relayLists.readUrls($user.pubkey).get()}) + const context = makeFeedContext({ + relays: $relayLists.readUrls($user.pubkey).get(), + withReplies: true, + }) const followList = $derived($followLists.one($user.pubkey)) const follows = $derived($followList?.pubkeys()) @@ -91,7 +94,7 @@ {:else} event.id} columnWidth={80} maxColumns={2} gap={3}> {#snippet child(event)} - + {/snippet} {#if loading} diff --git a/src/app/components/HomeNetworkItem.svelte b/src/app/components/HomeNetworkItem.svelte new file mode 100644 index 00000000..98dce5bf --- /dev/null +++ b/src/app/components/HomeNetworkItem.svelte @@ -0,0 +1,41 @@ + + +
+ + {#if nodes.length > 0} +
+ {#each nodes as node (node.comment.id)} + + {/each} +
+ {/if} +
diff --git a/src/app/feeds.ts b/src/app/feeds.ts index 8da944ec..4eac3e0b 100644 --- a/src/app/feeds.ts +++ b/src/app/feeds.ts @@ -5,6 +5,7 @@ import { COMMENT, DELETE, EVENT_TIME, + NOTE, addressTags, compareEventsAsc, getAddress, @@ -58,7 +59,17 @@ const getTargets = ({kind, tags}: TrustedEvent) => const getKeys = (event: TrustedEvent) => isReplaceableKind(event.kind) ? [event.id, getAddress(event)] : [event.id] -export const makeFeedContext = ({relays}: {relays: string[] | Promise}) => { +export const makeFeedContext = ({ + relays, + withReplies = false, +}: { + relays: string[] | Promise + withReplies?: boolean +}) => { + // Every feed loads NIP-22 comments. Kind 1 notes reply to each other with `e` tags instead, + // so a feed that renders those replies has to ask for them as well. + const contextKinds = withReplies ? [...EVENT_CONTEXT_KINDS, NOTE] : EVENT_CONTEXT_KINDS + const requestKinds = withReplies ? [...REACTION_KINDS, NOTE] : REACTION_KINDS const {repository} = app.get() const controller = new AbortController() const targets = new Set() @@ -134,7 +145,7 @@ export const makeFeedContext = ({relays}: {relays: string[] | Promise} // What's already local — an earlier page, our own optimistic reactions — never comes // through the update listener, so file it before asking the network for the rest for (const event of repository.query([ - ...getReplyFilters(events, {kinds: EVENT_CONTEXT_KINDS}), + ...getReplyFilters(events, {kinds: contextKinds}), ...getCommentFiltersForRoot(events), ])) { addEvent(event, touched) @@ -148,7 +159,7 @@ export const makeFeedContext = ({relays}: {relays: string[] | Promise} relays: urls, signal: controller.signal, filters: [ - ...getReplyFilters(events, {kinds: REACTION_KINDS}), + ...getReplyFilters(events, {kinds: requestKinds}), ...getCommentFiltersForRoot(events), ], }) @@ -170,7 +181,7 @@ export const makeFeedContext = ({relays}: {relays: string[] | Promise} const touched = new Set() for (const event of added) { - if (EVENT_CONTEXT_KINDS.includes(event.kind)) { + if (contextKinds.includes(event.kind)) { addEvent(event, touched) } }