From 072d28718336c27852d872c3577182f984156f8e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 10 Jul 2015 16:43:25 -0400 Subject: [PATCH] closes #3311 --- install/data/defaults.json | 3 ++- src/categories/recentreplies.js | 34 +++++++++++++++++++++++--- src/threadTools.js | 40 ++++++++++++++++++------------- src/topics/teaser.js | 11 ++++++--- src/views/admin/settings/post.tpl | 16 +++++++++++++ 5 files changed, 80 insertions(+), 24 deletions(-) diff --git a/install/data/defaults.json b/install/data/defaults.json index c8bcdb9008..462e006348 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -24,5 +24,6 @@ "maximumProfileImageSize": 256, "profileImageDimension": 128, "requireEmailConfirmation": 0, - "profile:allowProfileImageUploads": 1 + "profile:allowProfileImageUploads": 1, + "teaserPost": "last" } diff --git a/src/categories/recentreplies.js b/src/categories/recentreplies.js index bd6871ce99..f495ab1463 100644 --- a/src/categories/recentreplies.js +++ b/src/categories/recentreplies.js @@ -5,6 +5,7 @@ var async = require('async'), winston = require('winston'), _ = require('underscore'), + meta = require('../meta'), db = require('../database'), posts = require('../posts'), topics = require('../topics'), @@ -48,7 +49,11 @@ module.exports = function(Categories) { privileges.posts.filter('read', pids, uid, next); }, function(pids, next) { - posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next); + if (meta.config.teaserPost === 'first') { + getMainPosts(pids, uid, next); + } else { + posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next); + } }, function(posts, next) { categoryData.forEach(function(category) { @@ -59,10 +64,33 @@ module.exports = function(Categories) { ], callback); }; + function getMainPosts(pids, uid, callback) { + async.waterfall([ + function(next) { + var keys = pids.map(function(pid) { + return 'post:' + pid; + }); + db.getObjectsFields(keys, ['tid'], next); + }, + function(posts, next) { + var keys = posts.map(function(post) { + return 'topic:' + post.tid; + }); + db.getObjectsFields(keys, ['mainPid'], next); + }, + function(topics, next) { + var mainPids = topics.map(function(topic) { + return topic.mainPid; + }); + posts.getPostSummaryByPids(mainPids, uid, {stripTags: true}, next); + } + ], callback); + } + function assignPostsToCategory(category, posts) { category.posts = posts.filter(function(post) { - return post.category && (parseInt(post.category.cid, 10) === parseInt(category.cid, 10) - || parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10)); + return post.category && (parseInt(post.category.cid, 10) === parseInt(category.cid, 10) || + parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10)); }).sort(function(a, b) { return b.timestamp - a.timestamp; }).slice(0, parseInt(category.numRecentReplies, 10)); diff --git a/src/threadTools.js b/src/threadTools.js index 1b5c71451a..437cbec1b4 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -125,25 +125,31 @@ var async = require('async'), }; function togglePin(tid, uid, pin, callback) { - topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) { - if (err) { - return callback(err); - } - - topics.setTopicField(tid, 'pinned', pin ? 1 : 0); - db.sortedSetAdd('cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid); - - var data = { - tid: tid, - isPinned: pin, - uid: uid, - cid: topicData.cid - }; + var topicData; + async.waterfall([ + function(next) { + topics.getTopicFields(tid, ['cid', 'lastposttime'], next); + }, + function(_topicData, next) { + topicData = _topicData; + async.parallel([ + async.apply(topics.setTopicField, tid, 'pinned', pin ? 1 : 0), + async.apply(db.sortedSetAdd, 'cid:' + topicData.cid + ':tids', pin ? Math.pow(2, 53) : topicData.lastposttime, tid) + ], next); + }, + function(results, next) { + var data = { + tid: tid, + isPinned: pin, + uid: uid, + cid: topicData.cid + }; - plugins.fireHook('action:topic.pin', data); + plugins.fireHook('action:topic.pin', data); - callback(null, data); - }); + next(null, data); + } + ], callback); } ThreadTools.move = function(tid, cid, uid, callback) { diff --git a/src/topics/teaser.js b/src/topics/teaser.js index b02c4a5189..4558fb251a 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -5,6 +5,7 @@ var async = require('async'), S = require('string'), + meta = require('../meta'), db = require('../database'), user = require('../user'), posts = require('../posts'), @@ -24,8 +25,12 @@ module.exports = function(Topics) { topics.forEach(function(topic) { counts.push(topic && (parseInt(topic.postcount, 10) || 0)); - if (topic && topic.teaserPid) { - teaserPids.push(topic.teaserPid); + if (topic) { + if (meta.config.teaserPost === 'first') { + teaserPids.push(topic.mainPid); + } else { + teaserPids.push(topic.teaserPid); + } } }); @@ -65,7 +70,7 @@ module.exports = function(Topics) { return null; } if (tidToPost[topic.tid]) { - tidToPost[topic.tid].index = counts[index]; + tidToPost[topic.tid].index = meta.config.teaserPost === 'first' ? 1 : counts[index]; if (tidToPost[topic.tid].content) { var s = S(tidToPost[topic.tid].content); tidToPost[topic.tid].content = s.stripTags.apply(s, utils.stripTags).s; diff --git a/src/views/admin/settings/post.tpl b/src/views/admin/settings/post.tpl index 4f4314228d..1649b42e8c 100644 --- a/src/views/admin/settings/post.tpl +++ b/src/views/admin/settings/post.tpl @@ -66,6 +66,22 @@ +
+
Teaser Settings
+
+
+
+ + +
+
+
+
+ +
Signature Settings