|
|
|
|
@ -1,19 +1,21 @@
@@ -1,19 +1,21 @@
|
|
|
|
|
<script lang="ts"> |
|
|
|
|
import type { NDKEvent } from '@nostr-dev-kit/ndk' |
|
|
|
|
import EventCard from './EventCard.svelte' |
|
|
|
|
import ThreadWrapper from '$lib/components/events/ThreadWrapper.svelte' |
|
|
|
|
import { writable } from 'svelte/store' |
|
|
|
|
import ComposeReply from './ComposeReply.svelte' |
|
|
|
|
import type { ThreadTreeNode } from '$lib/components/events/type' |
|
|
|
|
import ThreadTree from './ThreadTree.svelte' |
|
|
|
|
|
|
|
|
|
export let event: NDKEvent |
|
|
|
|
export let type: 'proposal' | 'issue' = 'proposal' |
|
|
|
|
export let show_compose = true |
|
|
|
|
|
|
|
|
|
export let replies: NDKEvent[] | undefined = undefined |
|
|
|
|
|
|
|
|
|
const getParentId = (reply: NDKEvent): string | undefined => { |
|
|
|
|
let t = reply.tags.find((tag) => tag.length === 4 && tag[3] === 'reply') |
|
|
|
|
let t = |
|
|
|
|
reply.tags.find((tag) => tag.length === 4 && tag[3] === 'reply') || |
|
|
|
|
reply.tags.find((tag) => tag.length === 4 && tag[3] === 'root') || |
|
|
|
|
// include events that don't use nip 10 markers |
|
|
|
|
reply.tags.find((tag) => tag.length < 4 && tag[0] === 'e') |
|
|
|
|
return t ? t[1] : undefined |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -25,24 +27,28 @@
@@ -25,24 +27,28 @@
|
|
|
|
|
const thread_tree: ThreadTreeNode[] = [] |
|
|
|
|
replies.forEach((reply) => { |
|
|
|
|
let reply_parent_id = getParentId(reply) |
|
|
|
|
if (reply_parent_id && hashTable[reply_parent_id]) |
|
|
|
|
if (reply_parent_id && hashTable[reply_parent_id]) { |
|
|
|
|
hashTable[reply_parent_id].child_nodes.push(hashTable[reply.id]) |
|
|
|
|
else thread_tree.push(hashTable[reply.id]) |
|
|
|
|
hashTable[reply_parent_id].child_nodes.sort( |
|
|
|
|
(a, b) => (a.event.created_at || 0) - (b.event.created_at || 0) |
|
|
|
|
) |
|
|
|
|
} else thread_tree.push(hashTable[reply.id]) |
|
|
|
|
}) |
|
|
|
|
return thread_tree |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let thread_tree_store = writable(createThreadTree(replies ? replies : [])) |
|
|
|
|
let thread_tree_store = writable( |
|
|
|
|
createThreadTree(replies ? [event, ...replies] : [event]) |
|
|
|
|
) |
|
|
|
|
let thread_tree_root: ThreadTreeNode | undefined |
|
|
|
|
// TODO: add 'mentions' and secondary references that fall outside of root childNodes |
|
|
|
|
// they should appear in the UI as 'mentioned in' and be clear that replies ar enot incldued |
|
|
|
|
$: { |
|
|
|
|
if (replies) thread_tree_store.set(createThreadTree(replies)) |
|
|
|
|
if (replies) thread_tree_store.set(createThreadTree([event, ...replies])) |
|
|
|
|
thread_tree_root = $thread_tree_store.find((t) => t.event.id === event.id) |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<EventCard {type} {event} /> |
|
|
|
|
|
|
|
|
|
<ThreadWrapper num_replies={$thread_tree_store.length}> |
|
|
|
|
{#each $thread_tree_store as tree} |
|
|
|
|
<ThreadTree {type} {tree} /> |
|
|
|
|
{/each} |
|
|
|
|
<ComposeReply {type} reply_to_event_id={event.id} /> |
|
|
|
|
</ThreadWrapper> |
|
|
|
|
{#if thread_tree_root} |
|
|
|
|
<ThreadTree {type} tree={thread_tree_root} {show_compose} /> |
|
|
|
|
{/if} |
|
|
|
|
|