|
|
|
@ -10,7 +10,8 @@ var topics = require('./topics');
|
|
|
|
|
var privileges = require('./privileges');
|
|
|
|
|
var plugins = require('./plugins');
|
|
|
|
|
|
|
|
|
|
(function (Posts) {
|
|
|
|
|
var Posts = module.exports;
|
|
|
|
|
|
|
|
|
|
require('./posts/create')(Posts);
|
|
|
|
|
require('./posts/delete')(Posts);
|
|
|
|
|
require('./posts/edit')(Posts);
|
|
|
|
@ -40,14 +41,11 @@ var plugins = require('./plugins');
|
|
|
|
|
return callback(null, []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var keys = [];
|
|
|
|
|
|
|
|
|
|
for (var x = 0, numPids = pids.length; x < numPids; x += 1) {
|
|
|
|
|
keys.push('post:' + pids[x]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
var keys = pids.map(function (pid) {
|
|
|
|
|
return 'post:' + pid;
|
|
|
|
|
});
|
|
|
|
|
db.getObjects(keys, next);
|
|
|
|
|
},
|
|
|
|
|
function (posts, next) {
|
|
|
|
@ -103,32 +101,35 @@ var plugins = require('./plugins');
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
next(null, data.post);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Posts.getPostField = function (pid, field, callback) {
|
|
|
|
|
Posts.getPostFields(pid, [field], function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, data[field]);
|
|
|
|
|
});
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Posts.getPostFields(pid, [field], next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
next(null, data[field]);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Posts.getPostFields = function (pid, fields, callback) {
|
|
|
|
|
db.getObjectFields('post:' + pid, fields, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getObjectFields('post:' + pid, fields, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
data.pid = pid;
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:post.getFields', { posts: [data], fields: fields }, function (err, data) {
|
|
|
|
|
callback(err, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
plugins.fireHook('filter:post.getFields', { posts: [data], fields: fields }, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
next(null, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Posts.getPostsFields = function (pids, fields, callback) {
|
|
|
|
@ -140,49 +141,61 @@ var plugins = require('./plugins');
|
|
|
|
|
return 'post:' + pid;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
db.getObjectsFields(keys, fields, function (err, posts) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
plugins.fireHook('filter:post.getFields', { posts: posts, fields: fields }, function (err, data) {
|
|
|
|
|
callback(err, (data && Array.isArray(data.posts)) ? data.posts : null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.getObjectsFields(keys, fields, next);
|
|
|
|
|
},
|
|
|
|
|
function (posts, next) {
|
|
|
|
|
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) {
|
|
|
|
|
db.setObjectField('post:' + pid, field, value, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.setObjectField('post:' + pid, field, value, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
var data = {
|
|
|
|
|
pid: pid,
|
|
|
|
|
};
|
|
|
|
|
data[field] = value;
|
|
|
|
|
plugins.fireHook('action:post.setFields', { data: data });
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
next();
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Posts.setPostFields = function (pid, data, callback) {
|
|
|
|
|
db.setObject('post:' + pid, data, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.setObject('post:' + pid, data, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
data.pid = pid;
|
|
|
|
|
plugins.fireHook('action:post.setFields', { data: data });
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
next();
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Posts.getPidIndex = function (pid, tid, topicPostSort, callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
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)) {
|
|
|
|
|
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) {
|
|
|
|
@ -271,4 +284,3 @@ var plugins = require('./plugins');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}(exports));
|
|
|
|
|