return correct post count if its out of sync

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 805da98a36
commit b7eaf4191e

@ -2,12 +2,14 @@
var async = require('async');
var db = require('../database');
var topics = require('../topics');
var posts = require('../posts');
var websockets = require('./index');
var user = require('../user');
var meta = require('../meta');
var apiController = require('../controllers/api');
var privileges = require('../privileges');
var socketHelpers = require('./helpers');
var SocketTopics = module.exports;
@ -62,7 +64,33 @@ function postTopic(socket, data, 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) {

Loading…
Cancel
Save