mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
return correct post count if its out of sync
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user