Fetching and storing comments for self posts.
This commit is contained in:
@@ -1,7 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
function self(host, post) {
|
||||
console.log(post);
|
||||
function curateComments(comments) {
|
||||
return comments.map(comment => ({
|
||||
id: comment.id,
|
||||
url: `https://reddit.com${comment.permalink}`,
|
||||
author: comment.author.name,
|
||||
body: comment.body,
|
||||
html: comment.body_html,
|
||||
score: comment.score,
|
||||
datetime: new Date(comment.created * 1000),
|
||||
edited: comment.edited,
|
||||
controversiality: comment.controversiality,
|
||||
gilded: comment.gilded,
|
||||
stickied: comment.stickied,
|
||||
distinguished: comment.distinguished,
|
||||
locked: comment.locked,
|
||||
archived: comment.archived,
|
||||
parent: comment.parent_id,
|
||||
replies: comment.replies ? curateComments(comment.replies) : [],
|
||||
}));
|
||||
}
|
||||
|
||||
async function getFullPost(postId, reddit) {
|
||||
return reddit
|
||||
.getSubmission(postId)
|
||||
.expandReplies({
|
||||
limit: Infinity,
|
||||
depth: Infinity,
|
||||
})
|
||||
.fetch();
|
||||
}
|
||||
|
||||
async function self(host, originalPost, reddit) {
|
||||
const post = await getFullPost(originalPost.id, reddit) || originalPost;
|
||||
const curatedComments = curateComments(post.comments);
|
||||
|
||||
return {
|
||||
album: null,
|
||||
@@ -10,11 +42,13 @@ function self(host, post) {
|
||||
url: post.url,
|
||||
title: post.title,
|
||||
text: post.text,
|
||||
author: post.author.name,
|
||||
datetime: post.datetime,
|
||||
comments: curatedComments,
|
||||
type: 'text/plain',
|
||||
self: true,
|
||||
original: post,
|
||||
}]
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user