diff options
Diffstat (limited to 'gui/src/logic/trill')
| -rw-r--r-- | gui/src/logic/trill/helpers.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gui/src/logic/trill/helpers.ts b/gui/src/logic/trill/helpers.ts index 6b5a138..8bd1b0c 100644 --- a/gui/src/logic/trill/helpers.ts +++ b/gui/src/logic/trill/helpers.ts @@ -8,3 +8,27 @@ export function toFlat(n: FullNode): Poast { : Object.keys(n.children).map((c) => n.children[c].id), }; } + +type res = { threadChildren: FullNode[]; replies: FullNode[] }; +const bunt: res = { threadChildren: [], replies: [] }; +export function extractThread(node: FullNode): res { + if (!node.children) return bunt; + const r = Object.keys(node.children) + .sort() + .reduce((acc, index) => { + const n = node.children[index]; + // if (typeof n.post === "string") return acc; + const nn = n as FullNode; + return n.author !== node.author + ? { ...acc, replies: [...acc.replies, nn] } + : { + ...acc, + threadChildren: [ + ...acc.threadChildren, + nn, + ...extractThread(nn).threadChildren, + ], + }; + }, bunt); + return r; +} |
