Browse Source

Add `getChildAddresses` function to publication tree

master
buttercat1791 12 months ago
parent
commit
f1bdb20e21
  1. 17
      src/lib/data_structures/publication_tree.ts

17
src/lib/data_structures/publication_tree.ts

@ -129,6 +129,23 @@ export class PublicationTree implements AsyncIterable<NDKEvent> { @@ -129,6 +129,23 @@ export class PublicationTree implements AsyncIterable<NDKEvent> {
return event;
}
/**
* Retrieves the addresses of the loaded children, if any, of the node with the given address.
* @param address The address of the parent node.
* @returns An array of addresses of any loaded child nodes.
*/
async getChildAddresses(address: string): Promise<string[]> {
const node = await this.#nodes.get(address)?.value();
if (!node) {
throw new Error(`PublicationTree: Node with address ${address} not found.`);
}
return Promise.all(
node.children?.map(async child =>
(await child.value()).address
) ?? []
);
}
/**
* Retrieves the events in the hierarchy of the event with the given address.
* @param address The address of the event for which to retrieve the hierarchy.

Loading…
Cancel
Save