mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 08:55:47 +01:00
closes #3311
This commit is contained in:
@@ -24,5 +24,6 @@
|
|||||||
"maximumProfileImageSize": 256,
|
"maximumProfileImageSize": 256,
|
||||||
"profileImageDimension": 128,
|
"profileImageDimension": 128,
|
||||||
"requireEmailConfirmation": 0,
|
"requireEmailConfirmation": 0,
|
||||||
"profile:allowProfileImageUploads": 1
|
"profile:allowProfileImageUploads": 1,
|
||||||
|
"teaserPost": "last"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var async = require('async'),
|
|||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
|
|
||||||
|
meta = require('../meta'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
@@ -48,7 +49,11 @@ module.exports = function(Categories) {
|
|||||||
privileges.posts.filter('read', pids, uid, next);
|
privileges.posts.filter('read', pids, uid, next);
|
||||||
},
|
},
|
||||||
function(pids, 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) {
|
function(posts, next) {
|
||||||
categoryData.forEach(function(category) {
|
categoryData.forEach(function(category) {
|
||||||
@@ -59,10 +64,33 @@ module.exports = function(Categories) {
|
|||||||
], callback);
|
], 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) {
|
function assignPostsToCategory(category, posts) {
|
||||||
category.posts = posts.filter(function(post) {
|
category.posts = posts.filter(function(post) {
|
||||||
return post.category && (parseInt(post.category.cid, 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));
|
parseInt(post.category.parentCid, 10) === parseInt(category.cid, 10));
|
||||||
}).sort(function(a, b) {
|
}).sort(function(a, b) {
|
||||||
return b.timestamp - a.timestamp;
|
return b.timestamp - a.timestamp;
|
||||||
}).slice(0, parseInt(category.numRecentReplies, 10));
|
}).slice(0, parseInt(category.numRecentReplies, 10));
|
||||||
|
|||||||
@@ -125,25 +125,31 @@ var async = require('async'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
function togglePin(tid, uid, pin, callback) {
|
function togglePin(tid, uid, pin, callback) {
|
||||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
var topicData;
|
||||||
if (err) {
|
async.waterfall([
|
||||||
return callback(err);
|
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);
|
||||||
|
|
||||||
|
next(null, data);
|
||||||
}
|
}
|
||||||
|
], callback);
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
plugins.fireHook('action:topic.pin', data);
|
|
||||||
|
|
||||||
callback(null, data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadTools.move = function(tid, cid, uid, callback) {
|
ThreadTools.move = function(tid, cid, uid, callback) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
S = require('string'),
|
S = require('string'),
|
||||||
|
|
||||||
|
meta = require('../meta'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
@@ -24,8 +25,12 @@ module.exports = function(Topics) {
|
|||||||
|
|
||||||
topics.forEach(function(topic) {
|
topics.forEach(function(topic) {
|
||||||
counts.push(topic && (parseInt(topic.postcount, 10) || 0));
|
counts.push(topic && (parseInt(topic.postcount, 10) || 0));
|
||||||
if (topic && topic.teaserPid) {
|
if (topic) {
|
||||||
teaserPids.push(topic.teaserPid);
|
if (meta.config.teaserPost === 'first') {
|
||||||
|
teaserPids.push(topic.mainPid);
|
||||||
|
} else {
|
||||||
|
teaserPids.push(topic.teaserPid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -65,7 +70,7 @@ module.exports = function(Topics) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (tidToPost[topic.tid]) {
|
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) {
|
if (tidToPost[topic.tid].content) {
|
||||||
var s = S(tidToPost[topic.tid].content);
|
var s = S(tidToPost[topic.tid].content);
|
||||||
tidToPost[topic.tid].content = s.stripTags.apply(s, utils.stripTags).s;
|
tidToPost[topic.tid].content = s.stripTags.apply(s, utils.stripTags).s;
|
||||||
|
|||||||
@@ -66,6 +66,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Teaser Settings</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<form>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Teaser Post</label>
|
||||||
|
<select class="form-control" data-field="teaserPost">
|
||||||
|
<option value="last">Last</option>
|
||||||
|
<option value="first">First</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Signature Settings</div>
|
<div class="panel-heading">Signature Settings</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
|
|||||||
Reference in New Issue
Block a user