|
|
@ -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.getPostField = function(pid, field, callback) {
|
|
|
|
Posts.getPostFields(pid, [field], function(err, data) {
|
|
|
|
Posts.getPostFields(pid, [field], function(err, data) {
|
|
|
|
if(err) {
|
|
|
|
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) {
|
|
|
|
Posts.getPostsByUid = function(callerUid, uid, start, end, callback) {
|
|
|
|
user.getPostIds(uid, start, end, function(err, pids) {
|
|
|
|
user.getPostIds(uid, start, end, function(err, pids) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
@ -474,9 +504,22 @@ var async = require('async'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Posts.isOwner = function(pid, uid, callback) {
|
|
|
|
Posts.isOwner = function(pid, uid, callback) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
Posts.getPostField(pid, 'uid', function(err, author) {
|
|
|
|
callback(err, parseInt(author, 10) === parseInt(uid, 10));
|
|
|
|
callback(err, parseInt(author, 10) === uid);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Posts.isMain = function(pid, callback) {
|
|
|
|
Posts.isMain = function(pid, callback) {
|
|
|
|