Partially fix replies

This commit is contained in:
Lewis Dale committed 2023-10-09 08:57:48 +01:00
1 parent 640179587c
commit 8b6a712a62
2 files changed
+17 -12

No files matched your search

+12 -6
View File
@@ -52,6 +52,7 @@ class PostCache {
const comments = [...await this.fetchCommentsByType(), ...await this.fetchCommentsByType("webmention")];
comments.forEach(comment => {
console.log(comment.post);
if (this.posts[comment.post]) {
this.posts[comment.post].comments[comment.id] = comment;
}
@@ -94,7 +95,7 @@ const mapComment = comment => ({
url: comment.meta.semantic_linkbacks_author_url,
},
content: comment.content.rendered,
canonical: comment.meta.semantic_linkbacks_canonical,
canonical: comment.meta.url,
date: comment.date,
});
@@ -102,20 +103,25 @@ const mapComment = comment => ({
module.exports = async () => {
const cache = new PostCache();
await cache.fetchLatest();
return Object.values(cache.posts)
const posts = Object.values(cache.posts)
.sort(dateSort)
.map(post => ({
...post,
comments: Object.values(post.comments)
.sort(dateSort)
.reduce((comments, comment) => {
if (!comments[comment.meta.semantic_linkbacks_type]) {
comments[comment.meta.semantic_linkbacks_type] = [];
if (!comments[comment.type]) {
comments[comment.type] = [];
}
comments[comment.meta.semantic_linkbacks_type].push(mapComment(comment));
comments[comment.type].push(mapComment(comment));
return comments;
}, { like: [], reply: [], repost: [] })
}));
console.log(cache.posts[24].comments);
console.log(posts.find(post => post.id === 24)?.comments);
return posts;
};