Merge pull request #5568 from NodeBB/patch-pitaj

`filter:teasers.get` provided with `uid`
v1.18.x
Julian Lam 8 years ago committed by GitHub
commit 60990f28ad

@ -86,7 +86,7 @@ module.exports = function (Categories) {
privileges.topics.filterTids('read', tids, uid, next); privileges.topics.filterTids('read', tids, uid, next);
}, },
function (tids, next) { function (tids, next) {
getTopics(tids, next); getTopics(tids, uid, next);
}, },
function (topics, next) { function (topics, next) {
assignTopicsToCategories(categoryData, topics); assignTopicsToCategories(categoryData, topics);
@ -98,7 +98,7 @@ module.exports = function (Categories) {
], callback); ], callback);
}; };
function getTopics(tids, callback) { function getTopics(tids, uid, callback) {
var topicData; var topicData;
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -119,7 +119,7 @@ module.exports = function (Categories) {
async.parallel({ async.parallel({
categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']), categoryData: async.apply(Categories.getCategoriesFields, cids, ['cid', 'parentCid']),
teasers: async.apply(topics.getTeasers, _topicData), teasers: async.apply(topics.getTeasers, _topicData, uid),
}, next); }, next);
}, },
function (results, next) { function (results, next) {

@ -126,7 +126,7 @@ var social = require('./social');
Topics.getUserBookmarks(tids, uid, next); Topics.getUserBookmarks(tids, uid, next);
}, },
teasers: function (next) { teasers: function (next) {
Topics.getTeasers(topics, next); Topics.getTeasers(topics, uid, next);
}, },
tags: function (next) { tags: function (next) {
Topics.getTopicsTagsObjects(tids, next); Topics.getTopicsTagsObjects(tids, next);

@ -12,7 +12,11 @@ var plugins = require('../plugins');
var utils = require('../../public/src/utils'); var utils = require('../../public/src/utils');
module.exports = function (Topics) { module.exports = function (Topics) {
Topics.getTeasers = function (topics, callback) { Topics.getTeasers = function (topics, uid, callback) {
if (typeof uid === 'function') {
callback = uid;
uid = 0;
}
if (!Array.isArray(topics) || !topics.length) { if (!Array.isArray(topics) || !topics.length) {
return callback(null, []); return callback(null, []);
} }
@ -94,7 +98,7 @@ module.exports = function (Topics) {
return tidToPost[topic.tid]; return tidToPost[topic.tid];
}); });
plugins.fireHook('filter:teasers.get', { teasers: teasers }, next); plugins.fireHook('filter:teasers.get', { teasers: teasers, uid: uid }, next);
}, },
function (data, next) { function (data, next) {
next(null, data.teasers); next(null, data.teasers);
@ -102,7 +106,11 @@ module.exports = function (Topics) {
], callback); ], callback);
}; };
Topics.getTeasersByTids = function (tids, callback) { Topics.getTeasersByTids = function (tids, uid, callback) {
if (typeof uid === 'function') {
callback = uid;
uid = 0;
}
if (!Array.isArray(tids) || !tids.length) { if (!Array.isArray(tids) || !tids.length) {
return callback(null, []); return callback(null, []);
} }
@ -111,13 +119,17 @@ module.exports = function (Topics) {
Topics.getTopicsFields(tids, ['tid', 'postcount', 'teaserPid'], next); Topics.getTopicsFields(tids, ['tid', 'postcount', 'teaserPid'], next);
}, },
function (topics, next) { function (topics, next) {
Topics.getTeasers(topics, next); Topics.getTeasers(topics, uid, next);
}, },
], callback); ], callback);
}; };
Topics.getTeaser = function (tid, callback) { Topics.getTeaser = function (tid, uid, callback) {
Topics.getTeasersByTids([tid], function (err, teasers) { if (typeof uid === 'function') {
callback = uid;
uid = 0;
}
Topics.getTeasersByTids([tid], uid, function (err, teasers) {
callback(err, Array.isArray(teasers) && teasers.length ? teasers[0] : null); callback(err, Array.isArray(teasers) && teasers.length ? teasers[0] : null);
}); });
}; };

Loading…
Cancel
Save