|
|
@ -9,21 +9,22 @@ var Groups = require('./groups');
|
|
|
|
var plugins = require('./plugins');
|
|
|
|
var plugins = require('./plugins');
|
|
|
|
var privileges = require('./privileges');
|
|
|
|
var privileges = require('./privileges');
|
|
|
|
|
|
|
|
|
|
|
|
(function (Categories) {
|
|
|
|
var Categories = module.exports;
|
|
|
|
require('./categories/data')(Categories);
|
|
|
|
|
|
|
|
require('./categories/create')(Categories);
|
|
|
|
require('./categories/data')(Categories);
|
|
|
|
require('./categories/delete')(Categories);
|
|
|
|
require('./categories/create')(Categories);
|
|
|
|
require('./categories/topics')(Categories);
|
|
|
|
require('./categories/delete')(Categories);
|
|
|
|
require('./categories/unread')(Categories);
|
|
|
|
require('./categories/topics')(Categories);
|
|
|
|
require('./categories/activeusers')(Categories);
|
|
|
|
require('./categories/unread')(Categories);
|
|
|
|
require('./categories/recentreplies')(Categories);
|
|
|
|
require('./categories/activeusers')(Categories);
|
|
|
|
require('./categories/update')(Categories);
|
|
|
|
require('./categories/recentreplies')(Categories);
|
|
|
|
|
|
|
|
require('./categories/update')(Categories);
|
|
|
|
Categories.exists = function (cid, callback) {
|
|
|
|
|
|
|
|
|
|
|
|
Categories.exists = function (cid, callback) {
|
|
|
|
db.isSortedSetMember('categories:cid', cid, callback);
|
|
|
|
db.isSortedSetMember('categories:cid', cid, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoryById = function (data, callback) {
|
|
|
|
Categories.getCategoryById = function (data, callback) {
|
|
|
|
var category;
|
|
|
|
var category;
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
@ -63,40 +64,46 @@ var privileges = require('./privileges');
|
|
|
|
next(null, data.category);
|
|
|
|
next(null, data.category);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.isIgnored = function (cids, uid, callback) {
|
|
|
|
Categories.isIgnored = function (cids, uid, callback) {
|
|
|
|
db.isSortedSetMembers('uid:' + uid + ':ignored:cids', cids, callback);
|
|
|
|
db.isSortedSetMembers('uid:' + uid + ':ignored:cids', cids, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getPageCount = function (cid, uid, callback) {
|
|
|
|
Categories.getPageCount = function (cid, uid, callback) {
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
async.parallel({
|
|
|
|
async.parallel({
|
|
|
|
topicCount: async.apply(Categories.getCategoryField, cid, 'topic_count'),
|
|
|
|
topicCount: async.apply(Categories.getCategoryField, cid, 'topic_count'),
|
|
|
|
settings: async.apply(user.getSettings, uid),
|
|
|
|
settings: async.apply(user.getSettings, uid),
|
|
|
|
}, function (err, results) {
|
|
|
|
}, next);
|
|
|
|
if (err) {
|
|
|
|
},
|
|
|
|
return callback(err);
|
|
|
|
function (results, next) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!parseInt(results.topicCount, 10)) {
|
|
|
|
if (!parseInt(results.topicCount, 10)) {
|
|
|
|
return callback(null, 1);
|
|
|
|
return next(null, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
callback(null, Math.ceil(parseInt(results.topicCount, 10) / results.settings.topicsPerPage));
|
|
|
|
next(null, Math.ceil(parseInt(results.topicCount, 10) / results.settings.topicsPerPage));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getAllCategories = function (uid, callback) {
|
|
|
|
Categories.getAllCategories = function (uid, callback) {
|
|
|
|
db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
|
|
|
|
async.waterfall([
|
|
|
|
if (err || !Array.isArray(cids) || !cids.length) {
|
|
|
|
function (next) {
|
|
|
|
return callback(err, []);
|
|
|
|
db.getSortedSetRange('categories:cid', 0, -1, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (cids, next) {
|
|
|
|
|
|
|
|
if (!Array.isArray(cids) || !cids.length) {
|
|
|
|
|
|
|
|
return next(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategories(cids, uid, callback);
|
|
|
|
Categories.getCategories(cids, uid, next);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
|
|
|
|
Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) {
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
db.getSortedSetRange(set, 0, -1, next);
|
|
|
|
db.getSortedSetRange(set, 0, -1, next);
|
|
|
@ -108,20 +115,25 @@ var privileges = require('./privileges');
|
|
|
|
Categories.getCategories(cids, uid, next);
|
|
|
|
Categories.getCategories(cids, uid, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getModerators = function (cid, callback) {
|
|
|
|
Categories.getModerators = function (cid, callback) {
|
|
|
|
Groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, function (err, uids) {
|
|
|
|
async.waterfall([
|
|
|
|
if (err || !Array.isArray(uids) || !uids.length) {
|
|
|
|
function (next) {
|
|
|
|
return callback(err, []);
|
|
|
|
Groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (uids, next) {
|
|
|
|
|
|
|
|
if (!Array.isArray(uids) || !uids.length) {
|
|
|
|
|
|
|
|
return next(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], callback);
|
|
|
|
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getCategories = function (cids, uid, callback) {
|
|
|
|
Categories.getCategories = function (cids, uid, callback) {
|
|
|
|
if (!Array.isArray(cids)) {
|
|
|
|
if (!Array.isArray(cids)) {
|
|
|
|
return callback(new Error('[[error:invalid-cid]]'));
|
|
|
|
return callback(new Error('[[error:invalid-cid]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,6 +142,8 @@ var privileges = require('./privileges');
|
|
|
|
return callback(null, []);
|
|
|
|
return callback(null, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
async.parallel({
|
|
|
|
async.parallel({
|
|
|
|
categories: function (next) {
|
|
|
|
categories: function (next) {
|
|
|
|
Categories.getCategoriesData(cids, next);
|
|
|
|
Categories.getCategoriesData(cids, next);
|
|
|
@ -146,11 +160,9 @@ var privileges = require('./privileges');
|
|
|
|
hasRead: function (next) {
|
|
|
|
hasRead: function (next) {
|
|
|
|
Categories.hasReadCategories(cids, uid, next);
|
|
|
|
Categories.hasReadCategories(cids, uid, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, function (err, results) {
|
|
|
|
}, next);
|
|
|
|
if (err) {
|
|
|
|
},
|
|
|
|
return callback(err);
|
|
|
|
function (results, next) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uid = parseInt(uid, 10);
|
|
|
|
uid = parseInt(uid, 10);
|
|
|
|
results.categories.forEach(function (category, i) {
|
|
|
|
results.categories.forEach(function (category, i) {
|
|
|
|
if (category) {
|
|
|
|
if (category) {
|
|
|
@ -162,18 +174,19 @@ var privileges = require('./privileges');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
callback(null, results.categories);
|
|
|
|
next(null, results.categories);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
], callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getTagWhitelist = function (cids, callback) {
|
|
|
|
Categories.getTagWhitelist = function (cids, callback) {
|
|
|
|
var keys = cids.map(function (cid) {
|
|
|
|
var keys = cids.map(function (cid) {
|
|
|
|
return 'cid:' + cid + ':tag:whitelist';
|
|
|
|
return 'cid:' + cid + ':tag:whitelist';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
db.getSortedSetsMembers(keys, callback);
|
|
|
|
db.getSortedSetsMembers(keys, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function calculateTopicPostCount(category) {
|
|
|
|
function calculateTopicPostCount(category) {
|
|
|
|
if (!category) {
|
|
|
|
if (!category) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -194,9 +207,9 @@ var privileges = require('./privileges');
|
|
|
|
|
|
|
|
|
|
|
|
category.totalPostCount = postCount;
|
|
|
|
category.totalPostCount = postCount;
|
|
|
|
category.totalTopicCount = topicCount;
|
|
|
|
category.totalTopicCount = topicCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getParents = function (cids, callback) {
|
|
|
|
Categories.getParents = function (cids, callback) {
|
|
|
|
var categoriesData;
|
|
|
|
var categoriesData;
|
|
|
|
var parentCids;
|
|
|
|
var parentCids;
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
@ -225,9 +238,9 @@ var privileges = require('./privileges');
|
|
|
|
next(null, parentData);
|
|
|
|
next(null, parentData);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getChildren = function (cids, uid, callback) {
|
|
|
|
Categories.getChildren = function (cids, uid, callback) {
|
|
|
|
var categories = cids.map(function (cid) {
|
|
|
|
var categories = cids.map(function (cid) {
|
|
|
|
return { cid: cid };
|
|
|
|
return { cid: cid };
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -239,9 +252,9 @@ var privileges = require('./privileges');
|
|
|
|
return c && c.children;
|
|
|
|
return c && c.children;
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function getChildrenRecursive(category, uid, callback) {
|
|
|
|
function getChildrenRecursive(category, uid, callback) {
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
db.getSortedSetRange('cid:' + category.cid + ':children', 0, -1, next);
|
|
|
|
db.getSortedSetRange('cid:' + category.cid + ':children', 0, -1, next);
|
|
|
@ -267,9 +280,9 @@ var privileges = require('./privileges');
|
|
|
|
}, next);
|
|
|
|
}, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Categories.flattenCategories = function (allCategories, categoryData) {
|
|
|
|
Categories.flattenCategories = function (allCategories, categoryData) {
|
|
|
|
categoryData.forEach(function (category) {
|
|
|
|
categoryData.forEach(function (category) {
|
|
|
|
if (category) {
|
|
|
|
if (category) {
|
|
|
|
if (!category.parent) {
|
|
|
|
if (!category.parent) {
|
|
|
@ -281,15 +294,15 @@ var privileges = require('./privileges');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Recursively build tree
|
|
|
|
* Recursively build tree
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param categories {array} flat list of categories
|
|
|
|
* @param categories {array} flat list of categories
|
|
|
|
* @param parentCid {number} start from 0 to build full tree
|
|
|
|
* @param parentCid {number} start from 0 to build full tree
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
Categories.getTree = function (categories, parentCid) {
|
|
|
|
Categories.getTree = function (categories, parentCid) {
|
|
|
|
var tree = [];
|
|
|
|
var tree = [];
|
|
|
|
var i = 0;
|
|
|
|
var i = 0;
|
|
|
|
var len = categories.length;
|
|
|
|
var len = categories.length;
|
|
|
@ -308,9 +321,9 @@ var privileges = require('./privileges');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
return tree;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.buildForSelect = function (uid, callback) {
|
|
|
|
Categories.buildForSelect = function (uid, callback) {
|
|
|
|
function recursive(category, categoriesData, level) {
|
|
|
|
function recursive(category, categoriesData, level) {
|
|
|
|
if (category.link) {
|
|
|
|
if (category.link) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -341,13 +354,13 @@ var privileges = require('./privileges');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
callback(null, categoriesData);
|
|
|
|
callback(null, categoriesData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.getIgnorers = function (cid, start, stop, callback) {
|
|
|
|
Categories.getIgnorers = function (cid, start, stop, callback) {
|
|
|
|
db.getSortedSetRevRange('cid:' + cid + ':ignorers', start, stop, callback);
|
|
|
|
db.getSortedSetRevRange('cid:' + cid + ':ignorers', start, stop, callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Categories.filterIgnoringUids = function (cid, uids, callback) {
|
|
|
|
Categories.filterIgnoringUids = function (cid, uids, callback) {
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
db.isSortedSetMembers('cid:' + cid + ':ignorers', uids, next);
|
|
|
|
db.isSortedSetMembers('cid:' + cid + ':ignorers', uids, next);
|
|
|
@ -359,5 +372,4 @@ var privileges = require('./privileges');
|
|
|
|
next(null, readingUids);
|
|
|
|
next(null, readingUids);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
], callback);
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}(exports));
|
|
|
|
|
|
|
|