'use strict'; var async = require('async'), _ = require('underscore'), db = require('./database'), utils = require('../public/src/utils'), user = require('./user'), topics = require('./topics'), postTools = require('./postTools'), privileges = require('./privileges'), plugins = require('./plugins'); (function(Posts) { require('./posts/create')(Posts); require('./posts/delete')(Posts); require('./posts/user')(Posts); require('./posts/category')(Posts); require('./posts/summary')(Posts); require('./posts/recent')(Posts); require('./posts/flags')(Posts); Posts.exists = function(pid, callback) { db.isSortedSetMember('posts:pid', pid, callback); }; Posts.getPostsByTid = function(tid, set, start, end, uid, reverse, callback) { Posts.getPidsFromSet(set, start, end, reverse, function(err, pids) { if(err) { return callback(err); } if(!Array.isArray(pids) || !pids.length) { return callback(null, []); } Posts.getPostsByPids(pids, uid, callback); }); }; Posts.getPidsFromSet = function(set, start, end, reverse, callback) { if (isNaN(start) || isNaN(end)) { return callback(null, []); } db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, end, callback); }; Posts.getPostsByPids = function(pids, uid, callback) { var keys = []; for(var x=0, numPids=pids.length; x