style changes

v1.18.x
barisusakli 8 years ago
parent e5f7eed8ec
commit 0d1d8f3874

@ -10,44 +10,42 @@ var topics = require('./topics');
var privileges = require('./privileges'); var privileges = require('./privileges');
var plugins = require('./plugins'); var plugins = require('./plugins');
(function (Posts) { var Posts = module.exports;
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/tools')(Posts);
require('./posts/votes')(Posts);
require('./posts/bookmarks')(Posts);
Posts.exists = function (pid, callback) { 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/tools')(Posts);
require('./posts/votes')(Posts);
require('./posts/bookmarks')(Posts);
Posts.exists = function (pid, callback) {
db.isSortedSetMember('posts:pid', pid, callback); db.isSortedSetMember('posts:pid', pid, callback);
}; };
Posts.getPidsFromSet = function (set, start, stop, reverse, callback) { Posts.getPidsFromSet = function (set, start, stop, reverse, callback) {
if (isNaN(start) || isNaN(stop)) { if (isNaN(start) || isNaN(stop)) {
return callback(null, []); return callback(null, []);
} }
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback); db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback);
}; };
Posts.getPostsByPids = function (pids, uid, callback) { Posts.getPostsByPids = function (pids, uid, callback) {
if (!Array.isArray(pids) || !pids.length) { if (!Array.isArray(pids) || !pids.length) {
return callback(null, []); return callback(null, []);
} }
var keys = [];
for (var x = 0, numPids = pids.length; x < numPids; x += 1) {
keys.push('post:' + pids[x]);
}
async.waterfall([ async.waterfall([
function (next) { function (next) {
var keys = pids.map(function (pid) {
return 'post:' + pid;
});
db.getObjects(keys, next); db.getObjects(keys, next);
}, },
function (posts, next) { function (posts, next) {
@ -74,9 +72,9 @@ var plugins = require('./plugins');
next(null, data.posts); next(null, data.posts);
}, },
], callback); ], callback);
}; };
Posts.getPostSummariesFromSet = function (set, uid, start, stop, callback) { Posts.getPostSummariesFromSet = function (set, uid, start, stop, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSortedSetRevRange(set, start, stop, next); db.getSortedSetRevRange(set, start, stop, next);
@ -91,9 +89,9 @@ var plugins = require('./plugins');
next(null, { posts: posts, nextStart: stop + 1 }); next(null, { posts: posts, nextStart: stop + 1 });
}, },
], callback); ], callback);
}; };
Posts.getPostData = function (pid, callback) { Posts.getPostData = function (pid, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getObject('post:' + pid, next); db.getObject('post:' + pid, next);
@ -103,35 +101,38 @@ var plugins = require('./plugins');
}, },
function (data, next) { function (data, next) {
next(null, data.post); next(null, data.post);
} },
], callback); ], callback);
}; };
Posts.getPostField = function (pid, field, callback) {
Posts.getPostFields(pid, [field], function (err, data) {
if (err) {
return callback(err);
}
callback(null, data[field]); Posts.getPostField = function (pid, field, callback) {
}); async.waterfall([
}; function (next) {
Posts.getPostFields(pid, [field], next);
Posts.getPostFields = function (pid, fields, callback) { },
db.getObjectFields('post:' + pid, fields, function (err, data) { function (data, next) {
if (err) { next(null, data[field]);
return callback(err); },
} ], callback);
};
Posts.getPostFields = function (pid, fields, callback) {
async.waterfall([
function (next) {
db.getObjectFields('post:' + pid, fields, next);
},
function (data, next) {
data.pid = pid; data.pid = pid;
plugins.fireHook('filter:post.getFields', { posts: [data], fields: fields }, function (err, data) { plugins.fireHook('filter:post.getFields', { posts: [data], fields: fields }, next);
callback(err, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null); },
}); function (data, next) {
}); next(null, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
}; },
], callback);
};
Posts.getPostsFields = function (pids, fields, callback) { Posts.getPostsFields = function (pids, fields, callback) {
if (!Array.isArray(pids) || !pids.length) { if (!Array.isArray(pids) || !pids.length) {
return callback(null, []); return callback(null, []);
} }
@ -140,52 +141,64 @@ var plugins = require('./plugins');
return 'post:' + pid; return 'post:' + pid;
}); });
db.getObjectsFields(keys, fields, function (err, posts) { async.waterfall([
if (err) { function (next) {
return callback(err); db.getObjectsFields(keys, fields, next);
} },
plugins.fireHook('filter:post.getFields', { posts: posts, fields: fields }, function (err, data) { function (posts, next) {
callback(err, (data && Array.isArray(data.posts)) ? data.posts : null); plugins.fireHook('filter:post.getFields', { posts: posts, fields: fields }, next);
}); },
}); function (data, next) {
}; next(null, (data && Array.isArray(data.posts)) ? data.posts : null);
},
], callback);
};
Posts.setPostField = function (pid, field, value, callback) { Posts.setPostField = function (pid, field, value, callback) {
db.setObjectField('post:' + pid, field, value, function (err) { async.waterfall([
if (err) { function (next) {
return callback(err); db.setObjectField('post:' + pid, field, value, next);
} },
function (next) {
var data = { var data = {
pid: pid, pid: pid,
}; };
data[field] = value; data[field] = value;
plugins.fireHook('action:post.setFields', { data: data }); plugins.fireHook('action:post.setFields', { data: data });
callback(); next();
}); },
}; ], callback);
};
Posts.setPostFields = function (pid, data, callback) { Posts.setPostFields = function (pid, data, callback) {
db.setObject('post:' + pid, data, function (err) { async.waterfall([
if (err) { function (next) {
return callback(err); db.setObject('post:' + pid, data, next);
} },
function (next) {
data.pid = pid; data.pid = pid;
plugins.fireHook('action:post.setFields', { data: data }); plugins.fireHook('action:post.setFields', { data: data });
callback(); next();
}); },
}; ], callback);
};
Posts.getPidIndex = function (pid, tid, topicPostSort, callback) { Posts.getPidIndex = function (pid, tid, topicPostSort, callback) {
async.waterfall([
function (next) {
var set = topicPostSort === 'most_votes' ? 'tid:' + tid + ':posts:votes' : 'tid:' + tid + ':posts'; var set = topicPostSort === 'most_votes' ? 'tid:' + tid + ':posts:votes' : 'tid:' + tid + ':posts';
db.sortedSetRank(set, pid, function (err, index) { db.sortedSetRank(set, pid, next);
},
function (index, next) {
if (!utils.isNumber(index)) { if (!utils.isNumber(index)) {
return callback(err, 0); return next(null, 0);
} }
callback(err, parseInt(index, 10) + 1); next(null, parseInt(index, 10) + 1);
}); },
}; ], callback);
};
Posts.getPostIndices = function (posts, uid, callback) { Posts.getPostIndices = function (posts, uid, callback) {
if (!Array.isArray(posts) || !posts.length) { if (!Array.isArray(posts) || !posts.length) {
return callback(null, []); return callback(null, []);
} }
@ -221,9 +234,9 @@ var plugins = require('./plugins');
next(null, indices); next(null, indices);
}, },
], callback); ], callback);
}; };
Posts.updatePostVoteCount = function (postData, callback) { Posts.updatePostVoteCount = function (postData, callback) {
if (!postData || !postData.pid || !postData.tid) { if (!postData || !postData.pid || !postData.tid) {
return callback(); return callback();
} }
@ -261,14 +274,13 @@ var plugins = require('./plugins');
], function (err) { ], function (err) {
callback(err); callback(err);
}); });
}; };
Posts.modifyPostByPrivilege = function (post, isAdminOrMod) { Posts.modifyPostByPrivilege = function (post, isAdminOrMod) {
if (post.deleted && !(isAdminOrMod || post.selfPost)) { if (post.deleted && !(isAdminOrMod || post.selfPost)) {
post.content = '[[topic:post_is_deleted]]'; post.content = '[[topic:post_is_deleted]]';
if (post.user) { if (post.user) {
post.user.signature = ''; post.user.signature = '';
} }
} }
}; };
}(exports));

Loading…
Cancel
Save