From d3a62c13f6b4716a3a3c971175b5553e2f095b50 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Thu, 5 Jun 2025 08:45:13 -0500 Subject: [PATCH] Add a `getParent` abstraction to `SveltePublicationTree` --- .../publications/svelte_publication_tree.svelte.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/components/publications/svelte_publication_tree.svelte.ts b/src/lib/components/publications/svelte_publication_tree.svelte.ts index b956fd7..eb8e65f 100644 --- a/src/lib/components/publications/svelte_publication_tree.svelte.ts +++ b/src/lib/components/publications/svelte_publication_tree.svelte.ts @@ -28,6 +28,14 @@ export class SveltePublicationTree { return this.#publicationTree.getHierarchy(address); } + async getParent(address: string): Promise { + const hierarchy = await this.getHierarchy(address); + + // The last element in the hierarchy is the event with the given address, so the parent is the + // second to last element. + return hierarchy.at(-2) ?? null; + } + setBookmark(address: string) { this.#publicationTree.setBookmark(address); }