'use strict'; var async = require('async'); var _ = require('underscore'); var db = require('./database'); var utils = require('../public/src/utils'); var user = require('./user'); var topics = require('./topics'); var privileges = require('./privileges'); var plugins = require('./plugins'); (function(Posts) { require('./posts/create')(Posts); require('./posts/delete')(Posts); require('./posts/edit')(Posts); require('./posts/parse')(Posts); require('./posts/user')(Posts); require('./posts/topics')(Posts); require('./posts/category')(Posts); require('./posts/summary')(Posts); require('./posts/recent')(Posts); require('./posts/flags')(Posts); require('./posts/tools')(Posts); Posts.exists = function(pid, callback) { db.isSortedSetMember('posts:pid', pid, callback); }; Posts.getPidsFromSet = function(set, start, stop, reverse, callback) { if (isNaN(start) || isNaN(stop)) { return callback(null, []); } db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback); }; Posts.getPostsByPids = function(pids, uid, callback) { if (!Array.isArray(pids) || !pids.length) { return callback(null, []); } var keys = []; for (var x=0, numPids=pids.length; x 0) { db.sortedSetAdd('uid:' + postData.uid + ':posts:votes', postData.votes, postData.pid, next); } else { db.sortedSetRemove('uid:' + postData.uid + ':posts:votes', postData.pid, next); } } else { next(); } }, function (next) { async.waterfall([ function (next) { topics.getTopicField(postData.tid, 'mainPid', next); }, function (mainPid, next) { if (parseInt(mainPid, 10) === parseInt(postData.pid, 10)) { return next(); } db.sortedSetAdd('tid:' + postData.tid + ':posts:votes', postData.votes, postData.pid, next); } ], next); }, function (next) { Posts.setPostFields(postData.pid, {upvotes: postData.upvotes, downvotes: postData.downvotes}, next); } ], function(err) { callback(err); }); }; }(exports));