From 8eaff1492a0d7479ce7b42ca98d708ba0f0bcb12 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 28 Apr 2016 11:52:05 -0400 Subject: [PATCH] Added ACP option to customise recent post Before, could either be OP or last reply. Now, you can choose between OP, last reply, or last post (which includes OP) --- install/data/defaults.json | 2 +- src/categories/recentreplies.js | 9 +-------- src/topics/teaser.js | 25 +++++++++++++++++++++++-- src/views/admin/settings/post.tpl | 3 ++- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index 45f426fb04..4ddf385e8a 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -31,7 +31,7 @@ "profileImageDimension": 128, "requireEmailConfirmation": 0, "allowProfileImageUploads": 1, - "teaserPost": "last", + "teaserPost": "last-reply", "allowPrivateGroups": 1, "unreadCutoff": 2, "bookmarkThreshold": 5 diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index 7d42f053ff..e431a5cd59 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -105,14 +105,7 @@ module.exports = function(Categories) { function (next) { topics.getTopicsFields(tids, ['tid', 'mainPid', 'slug', 'title', 'teaserPid', 'cid', 'postcount'], next); }, - function (_topicData, next) { - topicData = _topicData; - topicData.forEach(function(topic) { - topic.teaserPid = topic.teaserPid || topic.mainPid; - }); - - topics.getTeasers(topicData, next); - }, + async.apply(topics.getTeasers, topicData), function (teasers, next) { teasers.forEach(function(teaser, index) { if (teaser) { diff --git a/src/topics/teaser.js b/src/topics/teaser.js index b841219a25..9c752946ee 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -26,7 +26,24 @@ module.exports = function(Topics) { topics.forEach(function(topic) { counts.push(topic && (parseInt(topic.postcount, 10) || 0)); if (topic) { - teaserPids.push(meta.config.teaserPost === 'first' ? topic.mainPid : topic.teaserPid); + if (topic.teaserPid === 'null') { + delete topic.teaserPid; + } + + switch(meta.config.teaserPost) { + case 'first': + teaserPids.push(topic.mainPid); + break; + + case 'last-post': + teaserPids.push(topic.teaserPid || topic.mainPid); + break; + + case 'last-reply': // intentional fall-through + default: + teaserPids.push(topic.teaserPid); + break; + } } }); @@ -113,7 +130,11 @@ module.exports = function(Topics) { } pid = pid || null; - Topics.setTopicField(tid, 'teaserPid', pid, callback); + if (pid) { + Topics.setTopicField(tid, 'teaserPid', pid, callback); + } else { + Topics.deleteTopicField(tid, 'teaserPid', callback); + } }); }; }; \ No newline at end of file diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl index e37f51a40c..0855a34333 100644 --- a/src/views/admin/settings/post.tpl +++ b/src/views/admin/settings/post.tpl @@ -83,7 +83,8 @@