mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: add filter:categories.updateRecentTid
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
var db = require('../database');
|
const db = require('../database');
|
||||||
var posts = require('../posts');
|
const posts = require('../posts');
|
||||||
var topics = require('../topics');
|
const topics = require('../topics');
|
||||||
var privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
var batch = require('../batch');
|
const plugins = require('../plugins');
|
||||||
|
const batch = require('../batch');
|
||||||
|
|
||||||
module.exports = function (Categories) {
|
module.exports = function (Categories) {
|
||||||
Categories.getRecentReplies = async function (cid, uid, count) {
|
Categories.getRecentReplies = async function (cid, uid, count) {
|
||||||
@@ -25,15 +26,16 @@ module.exports = function (Categories) {
|
|||||||
db.getObjectField('category:' + cid, 'numRecentReplies'),
|
db.getObjectField('category:' + cid, 'numRecentReplies'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (count < numRecentReplies) {
|
if (count >= numRecentReplies) {
|
||||||
return await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
|
const data = await db.getSortedSetRangeWithScores('cid:' + cid + ':recent_tids', 0, count - numRecentReplies);
|
||||||
}
|
const shouldRemove = !(data.length === 1 && count === 1 && data[0].value === String(tid));
|
||||||
const data = await db.getSortedSetRangeWithScores('cid:' + cid + ':recent_tids', 0, count - numRecentReplies);
|
if (data.length && shouldRemove) {
|
||||||
const shouldRemove = !(data.length === 1 && count === 1 && data[0].value === String(tid));
|
await db.sortedSetsRemoveRangeByScore(['cid:' + cid + ':recent_tids'], '-inf', data[data.length - 1].score);
|
||||||
if (data.length && shouldRemove) {
|
}
|
||||||
await db.sortedSetsRemoveRangeByScore(['cid:' + cid + ':recent_tids'], '-inf', data[data.length - 1].score);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
|
await db.sortedSetAdd('cid:' + cid + ':recent_tids', Date.now(), tid);
|
||||||
|
await plugins.fireHook('filter:categories.updateRecentTid', { cid: cid, tid: tid });
|
||||||
};
|
};
|
||||||
|
|
||||||
Categories.updateRecentTidForCid = async function (cid) {
|
Categories.updateRecentTidForCid = async function (cid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user