mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-03-14 04:08:32 +03:00
More checks on thread contexts
Some instances return really wacky order of posts
This commit is contained in:
parent
d55bd95c72
commit
1f5d74d78e
1 changed files with 28 additions and 0 deletions
|
@ -97,6 +97,34 @@ export function groupContext(items) {
|
|||
contexts[contextIndex++] = [item, repliedItem];
|
||||
}
|
||||
});
|
||||
|
||||
// Check for cross-item contexts
|
||||
// Merge contexts into one if they have a common item (same id)
|
||||
for (let i = 0; i < contexts.length; i++) {
|
||||
for (let j = i + 1; j < contexts.length; j++) {
|
||||
const commonItem = contexts[i].find((t) => contexts[j].includes(t));
|
||||
if (commonItem) {
|
||||
contexts[i] = [...contexts[i], ...contexts[j]];
|
||||
// Remove duplicate items
|
||||
contexts[i] = contexts[i].filter(
|
||||
(item, index, self) =>
|
||||
self.findIndex((t) => t.id === item.id) === index,
|
||||
);
|
||||
contexts.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort items by checking inReplyToId
|
||||
contexts.forEach((context) => {
|
||||
context.sort((a, b) => {
|
||||
if (a.inReplyToId === b.id) return -1;
|
||||
if (b.inReplyToId === a.id) return 1;
|
||||
return 0;
|
||||
});
|
||||
});
|
||||
|
||||
if (contexts.length) console.log('🧵 Contexts', contexts);
|
||||
|
||||
const newItems = [];
|
||||
|
|
Loading…
Add table
Reference in a new issue