summaryrefslogtreecommitdiff
path: root/gui/src/logic
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-11-12 07:11:07 +0700
committerpolwex <polwex@sortug.com>2025-11-12 07:11:07 +0700
commit284ce9ce7d9f81e54e91f917329d48926487fbf4 (patch)
tree7a156986323fd799e1457c8b7663806e32b2af7d /gui/src/logic
parent7305d67ff7f9e78b73326ef0e1f68a9613d34205 (diff)
fixes to engagement handling
Diffstat (limited to 'gui/src/logic')
-rw-r--r--gui/src/logic/trill/helpers.ts24
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;
+}