feat: add filter:categories.getRecentTopicReplies

pass req.query to getRecentTopicReplies
v1.18.x
Barış Soner Uşaklı 5 years ago
parent 7e42988489
commit aad0880f7c

@ -62,12 +62,24 @@ module.exports = function (Categories) {
}
};
Categories.getRecentTopicReplies = async function (categoryData, uid) {
Categories.getRecentTopicReplies = async function (categoryData, uid, query) {
if (!Array.isArray(categoryData) || !categoryData.length) {
return;
}
const categoriesToLoad = categoryData.filter(category => category && category.numRecentReplies && parseInt(category.numRecentReplies, 10) > 0);
const keys = categoriesToLoad.map(category => 'cid:' + category.cid + ':recent_tids');
const categoriesToLoad = categoryData.filter(c => c && c.numRecentReplies && parseInt(c.numRecentReplies, 10) > 0);
let keys = [];
if (plugins.hasListeners('filter:categories.getRecentTopicReplies')) {
const result = await plugins.fireHook('filter:categories.getRecentTopicReplies', {
categories: categoriesToLoad,
uid: uid,
query: query,
keys: [],
});
keys = result.keys;
} else {
keys = categoriesToLoad.map(c => 'cid:' + c.cid + ':recent_tids');
}
const results = await db.getSortedSetsMembers(keys);
let tids = _.uniq(_.flatten(results).filter(Boolean));

@ -19,7 +19,7 @@ categoriesController.list = async function (req, res) {
const categoryData = await categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find');
const tree = categories.getTree(categoryData, 0);
await categories.getRecentTopicReplies(categoryData, req.uid);
await categories.getRecentTopicReplies(categoryData, req.uid, req.query);
const data = {
title: meta.config.homePageTitle || '[[pages:home]]',

@ -88,7 +88,7 @@ categoryController.get = async function (req, res, next) {
if (categoryData.children.length) {
const allCategories = [];
categories.flattenCategories(allCategories, categoryData.children);
await categories.getRecentTopicReplies(allCategories, req.uid);
await categories.getRecentTopicReplies(allCategories, req.uid, req.query);
}
categoryData.title = translator.escape(categoryData.name);

@ -109,7 +109,7 @@ describe('Categories', function () {
uid: 0,
}, function (err, categoryData) {
assert.ifError(err);
Categories.getRecentTopicReplies(categoryData, 0, function (err) {
Categories.getRecentTopicReplies(categoryData, 0, {}, function (err) {
assert.ifError(err);
done();
});

Loading…
Cancel
Save