privileges.posts.get takes an array of pids now

This commit is contained in:
barisusakli
2014-06-28 14:59:01 -04:00
parent 6cd29a31a4
commit d57f183f42
7 changed files with 108 additions and 29 deletions

View File

@@ -344,6 +344,14 @@ var async = require('async'),
});
};
Posts.getPostsFields = function(pids, fields, callback) {
var keys = pids.map(function(pid) {
return 'post:' + pid;
});
db.getObjectsFields(keys, fields, callback);
};
Posts.getPostField = function(pid, field, callback) {
Posts.getPostFields(pid, [field], function(err, data) {
if(err) {
@@ -382,6 +390,28 @@ var async = require('async'),
});
};
Posts.getCidsByPids = function(pids, callback) {
Posts.getPostsFields(pids, ['tid'], function(err, posts) {
if (err) {
return callback(err);
}
var tids = posts.map(function(post) {
return post.tid;
});
topics.getTopicsFields(tids, ['cid'], function(err, topics) {
if (err) {
return callback(err);
}
var cids = topics.map(function(topic) {
return topic.cid;
});
callback(null, cids);
});
});
};
Posts.getPostsByUid = function(callerUid, uid, start, end, callback) {
user.getPostIds(uid, start, end, function(err, pids) {
if (err) {
@@ -474,9 +504,22 @@ var async = require('async'),
};
Posts.isOwner = function(pid, uid, callback) {
Posts.getPostField(pid, 'uid', function(err, author) {
callback(err, parseInt(author, 10) === parseInt(uid, 10));
});
uid = parseInt(uid, 10);
if (Array.isArray(pid)) {
Posts.getPostsFields(pid, ['uid'], function(err, posts) {
if (err) {
return callback(err);
}
posts = posts.map(function(post) {
return post && parseInt(post.uid, 10) === uid;
});
callback(null, posts);
});
} else {
Posts.getPostField(pid, 'uid', function(err, author) {
callback(err, parseInt(author, 10) === uid);
});
}
};
Posts.isMain = function(pid, callback) {