module.exports = function() { this.compilePostCommentsHtml = (comments, next_comment, post_id, post_url, morechildren_ids, post_author, viewing_comment) => { return new Promise((resolve, reject) => { (async () => { let comments_html function commentAuthor(comment, classlist, submitter, moderator) { let classes = classlist.join(' ') if (comment.author === '[deleted]') return `[deleted]` else return `${comment.author}${submitter || ''}${moderator || ''}` } if(comments.author !== undefined && comments.body_html !== undefined) { let classlist = [] let submitter_link = '' let moderator = false let submitter = false let edited_span = '' let controversial_span = '' if(post_author === comments.author) { classlist.push('submitter') submitter_link = `[S]` submitter = true } if(comments.distinguished === 'moderator') { classlist.push('green') moderator_badge = ` [M]` moderator = true } if(comments.score_hidden) { ups = `[score hidden]` } else { ups = `${kFormatter(comments.ups)} points` } if(comments.edited) { edited_span = `*` } if(comments.controversiality > 0) { controversial_span = `` } comments_html = `

${commentAuthor(comments, classlist, submitter && submitter_link, moderator && moderator_badge)}

${ups}

${timeDifference(comments.created)}${edited_span}

${comments.stickied ? 'stickied comment' : ''}

${commentAuthor(comments, classlist, submitter && submitter_link, moderator && moderator_badge)}

${comments.user_flair}

${ups}${controversial_span}

${timeDifference(comments.created)}${edited_span}

${comments.stickied ? 'stickied comment' : ''}

${unescape(comments.body_html)}
` } else { if(comments.children) { if(comments.children.length > 0) { let parent_id = comments.parent_id.split('_')[1] if(post_id === parent_id && !morechildren_ids) { comments_html = `
` } else { if(!morechildren_ids) { let load_comms_href = parent_id comments_html = ` ` } else { morechildren_ids = JSON.parse(morechildren_ids) comments_html = `
` } } } else { let link = comments.parent_id.split('_')[1] comments_html = ` ` } } } if(comments.replies) { for(var i = 0; i < comments.replies.length; i++) { let comment = comments.replies[i] if(comment.type !== 'load_more') { let classlist = [] let submitter_link = '' let moderator = false let submitter = false let ups = '' let edited_span = '' let controversial_span = '' if(post_author === comment.author) { classlist.push('submitter') submitter_link = `[S]` submitter = true } if(comment.distinguished === 'moderator') { classlist.push('green') moderator_badge = ` [M]` moderator = true } if(comment.score_hidden) { ups = `[score hidden]` } else { ups = `${kFormatter(comment.ups)} points` } if(comment.edited) { edited_span = `*` } if(comment.controversiality > 0) { controversial_span = `` } comments_html += `

${commentAuthor(comment, classlist, submitter && submitter_link, moderator && moderator_badge)}

${ups}

${timeDifference(comment.created)}${edited_span}

${comment.stickied ? 'stickied comment' : ''}

${commentAuthor(comment, classlist, submitter && submitter_link, moderator && moderator_badge)}

${comment.user_flair}

${ups}${controversial_span}

${timeDifference(comment.created)}${edited_span}

${comment.stickied ? 'stickied comment' : ''}

${unescape(comment.body_html)}
` let replies_html = '' if(comment.replies) { if(comment.replies.length) { for(var j = 0; j < comment.replies.length; j++) { let next_reply if(comment.replies[j+1]) { next_reply = comment.replies[j+1] } replies_html += await compilePostCommentsHtml(comment.replies[j], next_reply, post_id, post_url, null, post_author, viewing_comment) } } } comments_html += replies_html + '
' } else { if(comment.children.length > 0) { let parent_id = comment.parent_id.split('_')[1] let load_comms_href = parent_id comments_html += ` ` } else { let link = comment.parent_id.split('_')[1] comments_html = ` ` } } } } let next_comment_parent_id = null if(next_comment) { if(next_comment.parent_id) { next_comment_parent_id = next_comment.parent_id.split('_')[1] } } if((comments.replies || comments.author !== undefined) && next_comment_parent_id !== comments.id) { comments_html += `
` } next_comment_parent_id = null resolve(comments_html) })() }) } }