|
|
|
@ -8,13 +8,15 @@ var user = require('../user');
|
|
|
|
|
var topics = require('../topics');
|
|
|
|
|
var apiController = require('../controllers/api');
|
|
|
|
|
|
|
|
|
|
var SocketCategories = {};
|
|
|
|
|
var SocketCategories = module.exports;
|
|
|
|
|
|
|
|
|
|
SocketCategories.getRecentReplies = function (socket, cid, callback) {
|
|
|
|
|
categories.getRecentReplies(cid, socket.uid, 4, callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketCategories.get = function (socket, data, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
|
|
|
|
categories: function (next) {
|
|
|
|
@ -23,40 +25,43 @@ SocketCategories.get = function (socket, data, callback) {
|
|
|
|
|
async.apply(categories.getCategoriesData),
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
results.categories = results.categories.filter(function (category) {
|
|
|
|
|
return category && (!category.disabled || results.isAdmin);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, results.categories);
|
|
|
|
|
});
|
|
|
|
|
next(null, results.categories);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketCategories.getWatchedCategories = function (socket, data, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
categories: async.apply(categories.getCategoriesByPrivilege, 'cid:0:children', socket.uid, 'find'),
|
|
|
|
|
ignoredCids: async.apply(user.getIgnoredCategories, socket.uid),
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
var watchedCategories = results.categories.filter(function (category) {
|
|
|
|
|
return category && results.ignoredCids.indexOf(category.cid.toString()) === -1;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, watchedCategories);
|
|
|
|
|
});
|
|
|
|
|
next(null, watchedCategories);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketCategories.loadMore = function (socket, data, callback) {
|
|
|
|
|
if (!data) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userPrivileges;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
privileges: function (next) {
|
|
|
|
|
privileges.categories.get(data.cid, socket.uid, next);
|
|
|
|
@ -71,15 +76,13 @@ SocketCategories.loadMore = function (socket, data, callback) {
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.privileges.read) {
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
userPrivileges = results.privileges;
|
|
|
|
|
if (!userPrivileges.read) {
|
|
|
|
|
return callback(new Error('[[error:no-privileges]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var infScrollTopicsPerPage = 20;
|
|
|
|
|
var set = 'cid:' + data.cid + ':tids';
|
|
|
|
|
var reverse = false;
|
|
|
|
@ -119,22 +122,20 @@ SocketCategories.loadMore = function (socket, data, callback) {
|
|
|
|
|
uid: socket.uid,
|
|
|
|
|
targetUid: results.targetUid,
|
|
|
|
|
settings: results.settings,
|
|
|
|
|
}, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.modifyTopicsByPrivilege(data.topics, results.privileges);
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
categories.modifyTopicsByPrivilege(data.topics, userPrivileges);
|
|
|
|
|
|
|
|
|
|
data.privileges = results.privileges;
|
|
|
|
|
data.privileges = userPrivileges;
|
|
|
|
|
data.template = {
|
|
|
|
|
category: true,
|
|
|
|
|
name: 'category',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
callback(null, data);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
next(null, data);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketCategories.getPageCount = function (socket, cid, callback) {
|
|
|
|
@ -150,6 +151,8 @@ SocketCategories.getCategoriesByPrivilege = function (socket, privilege, callbac
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketCategories.getMoveCategories = function (socket, data, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
|
|
|
|
categories: function (next) {
|
|
|
|
@ -165,17 +168,16 @@ SocketCategories.getMoveCategories = function (socket, data, callback) {
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
results.categories = results.categories.filter(function (category) {
|
|
|
|
|
return category && (!category.disabled || results.isAdmin) && !category.link;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, results.categories);
|
|
|
|
|
});
|
|
|
|
|
next(null, results.categories);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketCategories.watch = function (socket, cid, callback) {
|
|
|
|
@ -231,5 +233,3 @@ SocketCategories.isModerator = function (socket, cid, callback) {
|
|
|
|
|
SocketCategories.getCategory = function (socket, cid, callback) {
|
|
|
|
|
apiController.getCategoryData(cid, socket.uid, callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = SocketCategories;
|
|
|
|
|