|
|
|
@ -7,11 +7,30 @@ interface PublicationTreeNode { |
|
|
|
children?: PublicationTreeNode[]; |
|
|
|
children?: PublicationTreeNode[]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add an iterator over the leaves of the tree.
|
|
|
|
export class PublicationTree implements Iterable<NDKEvent> { |
|
|
|
export class PublicationTree { |
|
|
|
/** |
|
|
|
|
|
|
|
* The root node of the tree. |
|
|
|
|
|
|
|
*/ |
|
|
|
private root: PublicationTreeNode; |
|
|
|
private root: PublicationTreeNode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* A map of addresses in the tree to their corresponding nodes. |
|
|
|
|
|
|
|
*/ |
|
|
|
private nodes: Map<string, PublicationTreeNode>; |
|
|
|
private nodes: Map<string, PublicationTreeNode>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* A map of addresses in the tree to their corresponding events. |
|
|
|
|
|
|
|
*/ |
|
|
|
private events: Map<string, NDKEvent>; |
|
|
|
private events: Map<string, NDKEvent>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The address of the last-visited node. Used for iteration and progressive retrieval. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private bookmark?: string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The NDK instance used to fetch events. |
|
|
|
|
|
|
|
*/ |
|
|
|
private ndk: NDK; |
|
|
|
private ndk: NDK; |
|
|
|
|
|
|
|
|
|
|
|
constructor(rootEvent: NDKEvent, ndk: NDK) { |
|
|
|
constructor(rootEvent: NDKEvent, ndk: NDK) { |
|
|
|
@ -70,6 +89,16 @@ export class PublicationTree { |
|
|
|
return event; |
|
|
|
return event; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Symbol.iterator](): Iterator<NDKEvent> { |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next(): IteratorResult<NDKEvent> { |
|
|
|
|
|
|
|
// TODO: Implement iteration from the bookmark over subsequent leaves.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { done: true, value: null }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// #region Private Methods
|
|
|
|
// #region Private Methods
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|