From 284ce9ce7d9f81e54e91f917329d48926487fbf4 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 12 Nov 2025 07:11:07 +0700 Subject: fixes to engagement handling --- gui/src/logic/trill/helpers.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'gui/src/logic') 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; +} -- cgit v1.2.3