mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: add hook to modify sorting options/fields
This commit is contained in:
@@ -159,18 +159,24 @@ module.exports = function (Topics) {
|
|||||||
return tids;
|
return tids;
|
||||||
}
|
}
|
||||||
|
|
||||||
const topicData = await Topics.getTopicsFields(tids, [
|
const { sortMap, fields } = await plugins.hooks.fire('filter:topics.sortOptions', {
|
||||||
'tid', 'timestamp', 'lastposttime', 'upvotes', 'downvotes', 'postcount', 'pinned',
|
params,
|
||||||
]);
|
fields: [
|
||||||
const sortMap = {
|
'tid', 'timestamp', 'lastposttime', 'upvotes', 'downvotes', 'postcount', 'pinned',
|
||||||
recent: sortRecent,
|
],
|
||||||
old: sortOld,
|
sortMap: {
|
||||||
create: sortCreate,
|
recent: sortRecent,
|
||||||
posts: sortPopular,
|
old: sortOld,
|
||||||
votes: sortVotes,
|
create: sortCreate,
|
||||||
views: sortViews,
|
posts: sortPopular,
|
||||||
};
|
votes: sortVotes,
|
||||||
const sortFn = sortMap[params.sort] || sortRecent;
|
views: sortViews,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(params.sort);
|
||||||
|
const topicData = await Topics.getTopicsFields(tids, fields);
|
||||||
|
const sortFn = sortMap.hasOwnProperty(params.sort) && sortMap[params.sort] ?
|
||||||
|
sortMap[params.sort] : sortRecent;
|
||||||
|
|
||||||
if (params.floatPinned) {
|
if (params.floatPinned) {
|
||||||
floatPinned(topicData, sortFn);
|
floatPinned(topicData, sortFn);
|
||||||
|
|||||||
Reference in New Issue
Block a user