|
|
|
@ -21,35 +21,28 @@ topicsController.get = function(req, res, next) {
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
privileges.topics.get(tid, uid, function(err, privileges) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
privileges.topics.get(tid, uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (privileges, next) {
|
|
|
|
|
if (!privileges.read) {
|
|
|
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userPrivileges = privileges;
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
user.getSettings(uid, function(err, settings) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.getSettings(uid, next);
|
|
|
|
|
},
|
|
|
|
|
function (settings, next) {
|
|
|
|
|
var postIndex = 0;
|
|
|
|
|
if (!settings.usePagination) {
|
|
|
|
|
postIndex = Math.max((req.params.post_index || 1) - (settings.postsPerPage), 0);
|
|
|
|
|
postIndex = Math.max((req.params.post_index || 1) - (settings.postsPerPage - 1), 0);
|
|
|
|
|
} else if (!req.query.page) {
|
|
|
|
|
var index = Math.max(parseInt((req.params.post_index || 0), 10), 0);
|
|
|
|
|
page = Math.ceil((index + 1) / settings.postsPerPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var start = (page - 1) * settings.postsPerPage + postIndex,
|
|
|
|
|
end = start + settings.postsPerPage - 1 + postIndex;
|
|
|
|
|
end = start + settings.postsPerPage - 1;
|
|
|
|
|
|
|
|
|
|
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
|
|
|
|
if (topicData) {
|
|
|
|
@ -60,7 +53,6 @@ topicsController.get = function(req, res, next) {
|
|
|
|
|
}
|
|
|
|
|
next(err, topicData);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function (topicData, next) {
|
|
|
|
|
var description = '';
|
|
|
|
|