From 45bf32bef7d16373ea10907b92d97dcda1c77b85 Mon Sep 17 00:00:00 2001 From: fatchan Date: Sun, 7 Jul 2019 22:16:27 +0000 Subject: [PATCH] correct omitted reply count --- db/posts.js | 9 +++++++-- views/mixins/post.pug | 13 ++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/db/posts.js b/db/posts.js index 20a0a897..bf0ee592 100644 --- a/db/posts.js +++ b/db/posts.js @@ -61,8 +61,13 @@ module.exports = { if (thread.replyposts > 5) { //dont show ALL backlinks on OP for previews on index page const firstPreviewId = thread.replies[0].postId; - const firstPreviewBacklinkIndex = thread.backlinks.map(bl => bl.postId).indexOf(firstPreviewId); - thread.previewbacklinks = thread.backlinks.slice(firstPreviewBacklinkIndex); + const latestPreviewBacklink = thread.backlinks.find(bl => { return bl.postId >= firstPreviewId }); + if (latestPreviewBacklink != null) { + const latestPreviewIndex = thread.backlinks.map(bl => bl.postId).indexOf(latestPreviewBacklink); + thread.previewbacklinks = thread.backlinks.slice(latestPreviewIndex); + } else { + thread.previewbacklinks = []; + } //cout omitted image and posts const numPreviewImages = replies.reduce((acc, post) => { return acc + post.files.length }, 0); thread.omittedimages = thread.replyfiles - numPreviewImages; diff --git a/views/mixins/post.pug b/views/mixins/post.pug index 9e436696..9f4e7598 100644 --- a/views/mixins/post.pug +++ b/views/mixins/post.pug @@ -94,11 +94,14 @@ mixin post(post, truncate, manage=false, globalmanage=false) blockquote.muted #{post.omittedposts} post(s)#{post.omittedimages > 0 ? ' and '+post.omittedimages+' image(s)' : ''} omitted. #[a(href=`${postURL}#${post.postId}`) View the full thread] if post.previewbacklinks .replies Replies: - each backlink in post.previewbacklinks - a.quote(href=`/${post.board}/thread/${post.thread || post.postId}.html#${backlink.postId}`) >>#{backlink.postId} - | - if post.previewbacklinks.length < post.backlinks.length - | + #{post.backlinks.length-post.previewbacklinks.length} reply link(s) omitted + if post.previewbacklinks.length === 0 + | #{post.backlinks.length-post.previewbacklinks.length} reply link(s) omitted + else + each backlink in post.previewbacklinks + a.quote(href=`/${post.board}/thread/${post.thread || post.postId}.html#${backlink.postId}`) >>#{backlink.postId} + | + if post.previewbacklinks.length < post.backlinks.length + | + #{post.backlinks.length-post.previewbacklinks.length} reply link(s) omitted else if post.backlinks && post.backlinks.length > 0 .replies Replies: each backlink in post.backlinks