mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-16 18:56:15 +01:00
categories refactor
This commit is contained in:
62
src/categories/recentreplies.js
Normal file
62
src/categories/recentreplies.js
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
db = require('./../database'),
|
||||
posts = require('./../posts'),
|
||||
topics = require('./../topics'),
|
||||
CategoryTools = require('./../categoryTools');
|
||||
|
||||
module.exports = function(Categories) {
|
||||
Categories.getRecentReplies = function(cid, uid, count, callback) {
|
||||
if(count === 0 || !count) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
CategoryTools.privileges(cid, uid, function(err, privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!privileges.read) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
db.getSortedSetRevRange('categories:recent_posts:cid:' + cid, 0, count - 1, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err, []);
|
||||
}
|
||||
|
||||
if (!pids || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
posts.getPostSummaryByPids(pids, true, callback);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Categories.moveRecentReplies = function(tid, oldCid, cid, callback) {
|
||||
function movePost(pid, callback) {
|
||||
posts.getPostField(pid, 'timestamp', function(err, timestamp) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
db.sortedSetRemove('categories:recent_posts:cid:' + oldCid, pid);
|
||||
db.sortedSetAdd('categories:recent_posts:cid:' + cid, timestamp, pid);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
topics.getPids(tid, function(err, pids) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.each(pids, movePost, callback);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user