basically add declutter like capabilities.

This commit is contained in:
Jason Schwarzenberger
2020-11-11 17:16:04 +13:00
parent 3169af3002
commit 164b7e72c4
16 changed files with 694 additions and 50 deletions
+21
View File
@@ -0,0 +1,21 @@
module.exports.disqusThread = data => {
const comments = data.response.posts.reduce((c, post) => ({
...c,
[post.id.toString()]: {
author: post.author.name,
authorLink: post.author.profileUrl,
date: post.createdAt,
text: post.raw_message,
score: post.points,
children: [],
id: post.id.toString(),
parent: (post.parent || '').toString(),
}
}), {});
Object.keys(comments).filter(id => !!comments[id].parent).forEach(id => {
const comment = comments[id];
comments[comment.parent].children.push(comment);
});
const parents = Object.keys(comments).filter(id => comments[id].parent).map(id => comments[id]);
return parents;
};