|
|
@ -2,12 +2,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
var async = require('async');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var db = require('../database');
|
|
|
|
var topics = require('../topics');
|
|
|
|
var topics = require('../topics');
|
|
|
|
var posts = require('../posts');
|
|
|
|
var posts = require('../posts');
|
|
|
|
var websockets = require('./index');
|
|
|
|
var websockets = require('./index');
|
|
|
|
var user = require('../user');
|
|
|
|
var user = require('../user');
|
|
|
|
var meta = require('../meta');
|
|
|
|
var meta = require('../meta');
|
|
|
|
var apiController = require('../controllers/api');
|
|
|
|
var apiController = require('../controllers/api');
|
|
|
|
|
|
|
|
var privileges = require('../privileges');
|
|
|
|
var socketHelpers = require('./helpers');
|
|
|
|
var socketHelpers = require('./helpers');
|
|
|
|
|
|
|
|
|
|
|
|
var SocketTopics = module.exports;
|
|
|
|
var SocketTopics = module.exports;
|
|
|
@ -62,7 +64,33 @@ function postTopic(socket, data, callback) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SocketTopics.postcount = function (socket, tid, callback) {
|
|
|
|
SocketTopics.postcount = function (socket, tid, callback) {
|
|
|
|
topics.getTopicField(tid, 'postcount', callback);
|
|
|
|
async.waterfall([
|
|
|
|
|
|
|
|
function (next) {
|
|
|
|
|
|
|
|
privileges.topics.can('read', tid, socket.uid, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (canRead, next) {
|
|
|
|
|
|
|
|
if (!canRead) {
|
|
|
|
|
|
|
|
return next(new Error('[[no-privileges]]'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
|
|
|
replyCount: function (next) {
|
|
|
|
|
|
|
|
db.sortedSetCard('tid:' + tid + ':posts', next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
topicData: function (next) {
|
|
|
|
|
|
|
|
topics.getTopicFields(tid, ['mainPid', 'postcount'], next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}, next);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
function (results, next) {
|
|
|
|
|
|
|
|
if (results.topicData.mainPid && parseInt(results.topicData.postcount, 10) === parseInt(results.replyCount, 10) + 1) {
|
|
|
|
|
|
|
|
return next(null, results.topicData.postcount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var postcount = results.replyCount + (results.topicData.mainPid ? 1 : 0);
|
|
|
|
|
|
|
|
topics.setTopicField(tid, 'postcount', postcount);
|
|
|
|
|
|
|
|
next(null, postcount);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
], callback);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SocketTopics.bookmark = function (socket, data, callback) {
|
|
|
|
SocketTopics.bookmark = function (socket, data, callback) {
|
|
|
|