mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-31 04:36:31 +02:00
Merge branch 'fix-some-code-lint' of https://github.com/HeeL/NodeBB into HeeL-fix-some-code-lint
This commit is contained in:
@@ -5,13 +5,13 @@ var async = require('async');
|
||||
var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.bookmark = function (pid, uid, callback) {
|
||||
toggleBookmark('bookmark', pid, uid, callback);
|
||||
};
|
||||
|
||||
Posts.unbookmark = function(pid, uid, callback) {
|
||||
Posts.unbookmark = function (pid, uid, callback) {
|
||||
toggleBookmark('unbookmark', pid, uid, callback);
|
||||
};
|
||||
|
||||
@@ -22,16 +22,16 @@ module.exports = function(Posts) {
|
||||
var isBookmarking = type === 'bookmark';
|
||||
|
||||
async.parallel({
|
||||
owner: function(next) {
|
||||
owner: function (next) {
|
||||
Posts.getPostField(pid, 'uid', next);
|
||||
},
|
||||
postData: function(next) {
|
||||
postData: function (next) {
|
||||
Posts.getPostFields(pid, ['pid', 'uid'], next);
|
||||
},
|
||||
hasBookmarked: function(next) {
|
||||
hasBookmarked: function (next) {
|
||||
Posts.hasBookmarked(pid, uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -45,24 +45,24 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
if (isBookmarking) {
|
||||
db.sortedSetAdd('uid:' + uid + ':bookmarks', Date.now(), pid, next);
|
||||
} else {
|
||||
db.sortedSetRemove('uid:' + uid + ':bookmarks', pid, next);
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db[isBookmarking ? 'setAdd' : 'setRemove']('pid:' + pid + ':users_bookmarked', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.setCount('pid:' + pid + ':users_bookmarked', next);
|
||||
},
|
||||
function(count, next) {
|
||||
function (count, next) {
|
||||
results.postData.bookmarks = count;
|
||||
Posts.setPostField(pid, 'bookmarks', count, next);
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -84,10 +84,10 @@ module.exports = function(Posts) {
|
||||
});
|
||||
}
|
||||
|
||||
Posts.hasBookmarked = function(pid, uid, callback) {
|
||||
Posts.hasBookmarked = function (pid, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
if (Array.isArray(pid)) {
|
||||
callback(null, pid.map(function() { return false; }));
|
||||
callback(null, pid.map(function () { return false; }));
|
||||
} else {
|
||||
callback(null, false);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
if (Array.isArray(pid)) {
|
||||
var sets = pid.map(function(pid) {
|
||||
var sets = pid.map(function (pid) {
|
||||
return 'pid:' + pid + ':users_bookmarked';
|
||||
});
|
||||
|
||||
|
||||
@@ -7,44 +7,44 @@ var _ = require('underscore');
|
||||
var db = require('../database');
|
||||
var topics = require('../topics');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getCidByPid = function(pid, callback) {
|
||||
Posts.getCidByPid = function (pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
Posts.getPostField(pid, 'tid', next);
|
||||
},
|
||||
function(tid, next) {
|
||||
function (tid, next) {
|
||||
topics.getTopicField(tid, 'cid', next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.getCidsByPids = function(pids, callback) {
|
||||
Posts.getPostsFields(pids, ['tid'], function(err, posts) {
|
||||
Posts.getCidsByPids = function (pids, callback) {
|
||||
Posts.getPostsFields(pids, ['tid'], function (err, posts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var tids = posts.map(function(post) {
|
||||
var tids = posts.map(function (post) {
|
||||
return post.tid;
|
||||
}).filter(function(tid, index, array) {
|
||||
}).filter(function (tid, index, array) {
|
||||
return tid && array.indexOf(tid) === index;
|
||||
});
|
||||
|
||||
topics.getTopicsFields(tids, ['cid'], function(err, topics) {
|
||||
topics.getTopicsFields(tids, ['cid'], function (err, topics) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var map = {};
|
||||
topics.forEach(function(topic, index) {
|
||||
topics.forEach(function (topic, index) {
|
||||
if (topic) {
|
||||
map[tids[index]] = topic.cid;
|
||||
}
|
||||
});
|
||||
|
||||
var cids = posts.map(function(post) {
|
||||
var cids = posts.map(function (post) {
|
||||
return map[post.tid];
|
||||
});
|
||||
|
||||
@@ -53,18 +53,18 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.filterPidsByCid = function(pids, cid, callback) {
|
||||
Posts.filterPidsByCid = function (pids, cid, callback) {
|
||||
if (!cid) {
|
||||
return callback(null, pids);
|
||||
}
|
||||
|
||||
if (!Array.isArray(cid) || cid.length === 1) {
|
||||
// Single cid
|
||||
db.isSortedSetMembers('cid:' + parseInt(cid, 10) + ':pids', pids, function(err, isMembers) {
|
||||
db.isSortedSetMembers('cid:' + parseInt(cid, 10) + ':pids', pids, function (err, isMembers) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
pids = pids.filter(function(pid, index) {
|
||||
pids = pids.filter(function (pid, index) {
|
||||
return pid && isMembers[index];
|
||||
});
|
||||
callback(null, pids);
|
||||
|
||||
@@ -11,9 +11,9 @@ var topics = require('../topics');
|
||||
var categories = require('../categories');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.create = function(data, callback) {
|
||||
Posts.create = function (data, callback) {
|
||||
// This is an internal method, consider using Topics.reply instead
|
||||
var uid = data.uid;
|
||||
var tid = data.tid;
|
||||
@@ -27,10 +27,10 @@ module.exports = function(Posts) {
|
||||
var postData;
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.incrObjectField('global', 'nextPid', next);
|
||||
},
|
||||
function(pid, next) {
|
||||
function (pid, next) {
|
||||
|
||||
postData = {
|
||||
'pid': pid,
|
||||
@@ -55,23 +55,23 @@ module.exports = function(Posts) {
|
||||
|
||||
plugins.fireHook('filter:post.save', postData, next);
|
||||
},
|
||||
function(postData, next) {
|
||||
function (postData, next) {
|
||||
plugins.fireHook('filter:post.create', {post: postData, data: data}, next);
|
||||
},
|
||||
function(data, next) {
|
||||
function (data, next) {
|
||||
postData = data.post;
|
||||
db.setObject('post:' + postData.pid, postData, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
user.onNewPostMade(postData, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
topics.onNewPostMade(postData, next);
|
||||
},
|
||||
function(next) {
|
||||
topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) {
|
||||
function (next) {
|
||||
topics.getTopicFields(tid, ['cid', 'pinned'], function (err, topicData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -79,20 +79,20 @@ module.exports = function(Posts) {
|
||||
categories.onNewPostMade(topicData.cid, topicData.pinned, postData, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('posts:pid', timestamp, postData.pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.incrObjectField('global', 'postCount', next);
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
plugins.fireHook('filter:post.get', postData, next);
|
||||
});
|
||||
},
|
||||
function(postData, next) {
|
||||
function (postData, next) {
|
||||
plugins.fireHook('action:post.save', _.clone(postData));
|
||||
next(null, postData);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ var topics = require('../topics');
|
||||
var user = require('../user');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.delete = function(pid, uid, callback) {
|
||||
Posts.delete = function (pid, uid, callback) {
|
||||
var postData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -28,13 +28,13 @@ module.exports = function(Posts) {
|
||||
},
|
||||
function (topicData, next) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
updateTopicTimestamp(topicData, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
topics.updateTeaser(postData.tid, next);
|
||||
}
|
||||
], next);
|
||||
@@ -46,7 +46,7 @@ module.exports = function(Posts) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.restore = function(pid, uid, callback) {
|
||||
Posts.restore = function (pid, uid, callback) {
|
||||
var postData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -65,13 +65,13 @@ module.exports = function(Posts) {
|
||||
function (topicData, next) {
|
||||
postData.cid = topicData.cid;
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
updateTopicTimestamp(topicData, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
topics.updateTeaser(postData.tid, next);
|
||||
}
|
||||
], next);
|
||||
@@ -112,7 +112,7 @@ module.exports = function(Posts) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
Posts.purge = function(pid, uid, callback) {
|
||||
Posts.purge = function (pid, uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Posts.exists(pid, next);
|
||||
@@ -143,7 +143,7 @@ module.exports = function(Posts) {
|
||||
function (next) {
|
||||
Posts.dismissFlag(pid, next);
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ module.exports = function(Posts) {
|
||||
};
|
||||
|
||||
function deletePostFromTopicAndUser(pid, callback) {
|
||||
Posts.getPostFields(pid, ['tid', 'uid'], function(err, postData) {
|
||||
Posts.getPostFields(pid, ['tid', 'uid'], function (err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -164,12 +164,12 @@ module.exports = function(Posts) {
|
||||
'tid:' + postData.tid + ':posts',
|
||||
'tid:' + postData.tid + ':posts:votes',
|
||||
'uid:' + postData.uid + ':posts'
|
||||
], pid, function(err) {
|
||||
], pid, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], function(err, topicData) {
|
||||
topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], function (err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -184,19 +184,19 @@ module.exports = function(Posts) {
|
||||
function (next) {
|
||||
topics.decreasePostCount(postData.tid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
topics.updateTeaser(postData.tid, next);
|
||||
},
|
||||
function (next) {
|
||||
updateTopicTimestamp(topicData, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
user.incrementUserPostCountBy(postData.uid, -1, next);
|
||||
}
|
||||
], callback);
|
||||
@@ -206,12 +206,12 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
function deletePostFromCategoryRecentPosts(pid, callback) {
|
||||
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
||||
db.getSortedSetRange('categories:cid', 0, -1, function (err, cids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var sets = cids.map(function(cid) {
|
||||
var sets = cids.map(function (cid) {
|
||||
return 'cid:' + cid + ':pids';
|
||||
});
|
||||
|
||||
@@ -220,16 +220,16 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
function deletePostFromUsersBookmarks(pid, callback) {
|
||||
db.getSetMembers('pid:' + pid + ':users_bookmarked', function(err, uids) {
|
||||
db.getSetMembers('pid:' + pid + ':users_bookmarked', function (err, uids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var sets = uids.map(function(uid) {
|
||||
var sets = uids.map(function (uid) {
|
||||
return 'uid:' + uid + ':bookmarks';
|
||||
});
|
||||
|
||||
db.sortedSetsRemove(sets, pid, function(err) {
|
||||
db.sortedSetsRemove(sets, pid, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -241,33 +241,33 @@ module.exports = function(Posts) {
|
||||
|
||||
function deletePostFromUsersVotes(pid, callback) {
|
||||
async.parallel({
|
||||
upvoters: function(next) {
|
||||
upvoters: function (next) {
|
||||
db.getSetMembers('pid:' + pid + ':upvote', next);
|
||||
},
|
||||
downvoters: function(next) {
|
||||
downvoters: function (next) {
|
||||
db.getSetMembers('pid:' + pid + ':downvote', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var upvoterSets = results.upvoters.map(function(uid) {
|
||||
var upvoterSets = results.upvoters.map(function (uid) {
|
||||
return 'uid:' + uid + ':upvote';
|
||||
});
|
||||
|
||||
var downvoterSets = results.downvoters.map(function(uid) {
|
||||
var downvoterSets = results.downvoters.map(function (uid) {
|
||||
return 'uid:' + uid + ':downvote';
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetsRemove(upvoterSets, pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetsRemove(downvoterSets, pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.deleteAll(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], next);
|
||||
}
|
||||
], callback);
|
||||
|
||||
@@ -13,13 +13,13 @@ var cache = require('./cache');
|
||||
var pubsub = require('../pubsub');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
pubsub.on('post:edit', function(pid) {
|
||||
pubsub.on('post:edit', function (pid) {
|
||||
cache.del(pid);
|
||||
});
|
||||
|
||||
Posts.edit = function(data, callback) {
|
||||
Posts.edit = function (data, callback) {
|
||||
var postData;
|
||||
var results;
|
||||
|
||||
@@ -53,10 +53,10 @@ module.exports = function(Posts) {
|
||||
},
|
||||
function (next) {
|
||||
async.parallel({
|
||||
editor: function(next) {
|
||||
editor: function (next) {
|
||||
user.getUserFields(data.uid, ['username', 'userslug'], next);
|
||||
},
|
||||
topic: function(next) {
|
||||
topic: function (next) {
|
||||
editMainPost(data, postData, next);
|
||||
}
|
||||
}, next);
|
||||
@@ -85,13 +85,13 @@ module.exports = function(Posts) {
|
||||
var title = data.title ? data.title.trim() : '';
|
||||
|
||||
async.parallel({
|
||||
topic: function(next) {
|
||||
topic: function (next) {
|
||||
topics.getTopicFields(tid, ['cid', 'title'], next);
|
||||
},
|
||||
isMain: function(next) {
|
||||
isMain: function (next) {
|
||||
Posts.isMain(data.pid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -122,19 +122,19 @@ module.exports = function(Posts) {
|
||||
data.tags = data.tags || [];
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
plugins.fireHook('filter:topic.edit', {req: data.req, topic: topicData, data: data}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
function (results, next) {
|
||||
db.setObject('topic:' + tid, results.topic, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
topics.updateTags(tid, data.tags, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
topics.getTopicTagsObjects(tid, next);
|
||||
},
|
||||
function(tags, next) {
|
||||
function (tags, next) {
|
||||
topicData.tags = data.tags;
|
||||
plugins.fireHook('action:topic.edit', topicData);
|
||||
next(null, {
|
||||
|
||||
@@ -8,21 +8,21 @@ var db = require('../database');
|
||||
var user = require('../user');
|
||||
var analytics = require('../analytics');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.flag = function(post, uid, reason, callback) {
|
||||
Posts.flag = function (post, uid, reason, callback) {
|
||||
if (!parseInt(uid, 10) || !reason) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
async.parallel({
|
||||
hasFlagged: async.apply(hasFlagged, post.pid, uid),
|
||||
exists: async.apply(Posts.exists, post.pid)
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
function (results, next) {
|
||||
if (!results.exists) {
|
||||
return next(new Error('[[error:no-post]]'));
|
||||
}
|
||||
@@ -33,22 +33,22 @@ module.exports = function(Posts) {
|
||||
|
||||
var now = Date.now();
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('posts:flagged', now, post.pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetIncrBy('posts:flags:count', 1, post.pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.incrObjectField('post:' + post.pid, 'flags', next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('pid:' + post.pid + ':flag:uids', now, uid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetAdd('pid:' + post.pid + ':flag:uid:reason', 0, uid + ':' + reason, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
if (parseInt(post.uid, 10)) {
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetIncrBy, 'users:flags', 1, post.uid),
|
||||
@@ -61,14 +61,14 @@ module.exports = function(Posts) {
|
||||
}
|
||||
], next);
|
||||
},
|
||||
function(data, next) {
|
||||
function (data, next) {
|
||||
if (data[1] === 1) { // Only update state on new flag
|
||||
Posts.updateFlagData(uid, post.pid, {
|
||||
state: 'open'
|
||||
}, next);
|
||||
}
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -81,17 +81,17 @@ module.exports = function(Posts) {
|
||||
db.isSortedSetMember('pid:' + pid + ':flag:uids', uid, callback);
|
||||
}
|
||||
|
||||
Posts.dismissFlag = function(pid, callback) {
|
||||
Posts.dismissFlag = function (pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.getObjectFields('post:' + pid, ['pid', 'uid', 'flags'], next);
|
||||
},
|
||||
function(postData, next) {
|
||||
function (postData, next) {
|
||||
if (!postData.pid) {
|
||||
return callback();
|
||||
}
|
||||
async.parallel([
|
||||
function(next) {
|
||||
function (next) {
|
||||
if (parseInt(postData.uid, 10)) {
|
||||
if (parseInt(postData.flags, 10) > 0) {
|
||||
async.parallel([
|
||||
@@ -105,22 +105,22 @@ module.exports = function(Posts) {
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.sortedSetsRemove([
|
||||
'posts:flagged',
|
||||
'posts:flags:count',
|
||||
'uid:' + postData.uid + ':flag:pids'
|
||||
], pid, next);
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
async.series([
|
||||
function(next) {
|
||||
db.getSortedSetRange('pid:' + pid + ':flag:uids', 0, -1, function(err, uids) {
|
||||
function (next) {
|
||||
db.getSortedSetRange('pid:' + pid + ':flag:uids', 0, -1, function (err, uids) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(uids, function(uid, next) {
|
||||
async.each(uids, function (uid, next) {
|
||||
var nid = 'post_flag:' + pid + ':uid:' + uid;
|
||||
async.parallel([
|
||||
async.apply(db.delete, 'notifications:' + nid),
|
||||
@@ -137,14 +137,14 @@ module.exports = function(Posts) {
|
||||
async.apply(db.deleteObjectFields, 'post:' + pid, ['flag:state', 'flag:assignee', 'flag:notes', 'flag:history'])
|
||||
], next);
|
||||
},
|
||||
function(results, next) {
|
||||
function (results, next) {
|
||||
db.sortedSetsRemoveRangeByScore(['users:flags'], '-inf', 0, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.dismissAllFlags = function(callback) {
|
||||
db.getSortedSetRange('posts:flagged', 0, -1, function(err, pids) {
|
||||
Posts.dismissAllFlags = function (callback) {
|
||||
db.getSortedSetRange('posts:flagged', 0, -1, function (err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -152,8 +152,8 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.dismissUserFlags = function(uid, callback) {
|
||||
db.getSortedSetRange('uid:' + uid + ':flag:pids', 0, -1, function(err, pids) {
|
||||
Posts.dismissUserFlags = function (uid, callback) {
|
||||
db.getSortedSetRange('uid:' + uid + ':flag:pids', 0, -1, function (err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getFlags = function(set, cid, uid, start, stop, callback) {
|
||||
Posts.getFlags = function (set, cid, uid, start, stop, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
if (Array.isArray(set)) {
|
||||
@@ -192,31 +192,31 @@ module.exports = function(Posts) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
uidsReasons: function(next) {
|
||||
async.map(pids, function(pid, next) {
|
||||
uidsReasons: function (next) {
|
||||
async.map(pids, function (pid, next) {
|
||||
db.getSortedSetRange('pid:' + pid + ':flag:uid:reason', 0, -1, next);
|
||||
}, next);
|
||||
},
|
||||
posts: function(next) {
|
||||
posts: function (next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: false, extraFields: ['flags', 'flag:assignee', 'flag:state', 'flag:notes', 'flag:history']}, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
async.map(results.uidsReasons, function(uidReasons, next) {
|
||||
async.map(uidReasons, function(uidReason, next) {
|
||||
async.map(results.uidsReasons, function (uidReasons, next) {
|
||||
async.map(uidReasons, function (uidReason, next) {
|
||||
var uid = uidReason.split(':')[0];
|
||||
var reason = uidReason.substr(uidReason.indexOf(':') + 1);
|
||||
user.getUserFields(uid, ['username', 'userslug', 'picture'], function(err, userData) {
|
||||
user.getUserFields(uid, ['username', 'userslug', 'picture'], function (err, userData) {
|
||||
next(err, {user: userData, reason: reason});
|
||||
});
|
||||
}, next);
|
||||
}, function(err, reasons) {
|
||||
}, function (err, reasons) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
results.posts.forEach(function(post, index) {
|
||||
results.posts.forEach(function (post, index) {
|
||||
if (post) {
|
||||
post.flagReasons = reasons[index];
|
||||
}
|
||||
@@ -226,9 +226,9 @@ module.exports = function(Posts) {
|
||||
});
|
||||
},
|
||||
async.apply(Posts.expandFlagHistory),
|
||||
function(posts, next) {
|
||||
function (posts, next) {
|
||||
// Parse out flag data into its own object inside each post hash
|
||||
posts = posts.map(function(postObj) {
|
||||
posts = posts.map(function (postObj) {
|
||||
for(var prop in postObj) {
|
||||
postObj.flagData = postObj.flagData || {};
|
||||
|
||||
@@ -264,13 +264,13 @@ module.exports = function(Posts) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
Posts.updateFlagData = function(uid, pid, flagObj, callback) {
|
||||
Posts.updateFlagData = function (uid, pid, flagObj, callback) {
|
||||
// Retrieve existing flag data to compare for history-saving purposes
|
||||
var changes = [];
|
||||
var changeset = {};
|
||||
var prop;
|
||||
|
||||
Posts.getPostData(pid, function(err, postData) {
|
||||
Posts.getPostData(pid, function (err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -293,7 +293,7 @@ module.exports = function(Posts) {
|
||||
}
|
||||
}
|
||||
|
||||
changeset = changes.reduce(function(memo, prop) {
|
||||
changeset = changes.reduce(function (memo, prop) {
|
||||
memo['flag:' + prop] = flagObj[prop];
|
||||
return memo;
|
||||
}, {});
|
||||
@@ -303,7 +303,7 @@ module.exports = function(Posts) {
|
||||
try {
|
||||
var history = JSON.parse(postData['flag:history'] || '[]');
|
||||
|
||||
changes.forEach(function(property) {
|
||||
changes.forEach(function (property) {
|
||||
switch(property) {
|
||||
case 'assignee': // intentional fall-through
|
||||
case 'state':
|
||||
@@ -339,9 +339,9 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.expandFlagHistory = function(posts, callback) {
|
||||
Posts.expandFlagHistory = function (posts, callback) {
|
||||
// Expand flag history
|
||||
async.map(posts, function(post, next) {
|
||||
async.map(posts, function (post, next) {
|
||||
var history;
|
||||
try {
|
||||
history = JSON.parse(post['flag:history'] || '[]');
|
||||
@@ -350,12 +350,12 @@ module.exports = function(Posts) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
async.map(history, function(event, next) {
|
||||
async.map(history, function (event, next) {
|
||||
event.timestampISO = new Date(event.timestamp).toISOString();
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
user.getUserFields(event.uid, ['username', 'picture'], function(err, userData) {
|
||||
function (next) {
|
||||
user.getUserFields(event.uid, ['username', 'picture'], function (err, userData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -364,9 +364,9 @@ module.exports = function(Posts) {
|
||||
next();
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
if (event.type === 'assignee') {
|
||||
user.getUserField(parseInt(event.value, 10), 'username', function(err, username) {
|
||||
user.getUserField(parseInt(event.value, 10), 'username', function (err, username) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -381,10 +381,10 @@ module.exports = function(Posts) {
|
||||
setImmediate(next);
|
||||
}
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
next(err, event);
|
||||
});
|
||||
}, function(err, history) {
|
||||
}, function (err, history) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ var translator = require('../../public/src/modules/translator');
|
||||
|
||||
var urlRegex = /href="([^"]+)"/g;
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.parsePost = function(postData, callback) {
|
||||
Posts.parsePost = function (postData, callback) {
|
||||
postData.content = postData.content || '';
|
||||
|
||||
if (postData.pid && cache.has(String(postData.pid))) {
|
||||
@@ -25,7 +25,7 @@ module.exports = function(Posts) {
|
||||
postData.content = postData.content.toString();
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) {
|
||||
plugins.fireHook('filter:parse.post', {postData: postData}, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -40,13 +40,13 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.parseSignature = function(userData, uid, callback) {
|
||||
Posts.parseSignature = function (userData, uid, callback) {
|
||||
userData.signature = userData.signature || '';
|
||||
|
||||
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
||||
};
|
||||
|
||||
Posts.relativeToAbsolute = function(content) {
|
||||
Posts.relativeToAbsolute = function (content) {
|
||||
// Turns relative links in post body to absolute urls
|
||||
var parsed, current, absolute;
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ var async = require('async'),
|
||||
privileges = require('../privileges');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000
|
||||
};
|
||||
|
||||
Posts.getRecentPosts = function(uid, start, stop, term, callback) {
|
||||
Posts.getRecentPosts = function (uid, start, stop, term, callback) {
|
||||
var min = 0;
|
||||
if (terms[term]) {
|
||||
min = Date.now() - terms[term];
|
||||
@@ -21,30 +21,30 @@ module.exports = function(Posts) {
|
||||
var count = parseInt(stop, 10) === -1 ? stop : stop - start + 1;
|
||||
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.getSortedSetRevRangeByScore('posts:pid', start, count, '+inf', min, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
function (pids, next) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
function (pids, next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.getRecentPosterUids = function(start, stop, callback) {
|
||||
Posts.getRecentPosterUids = function (start, stop, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.getSortedSetRevRange('posts:pid', start, stop, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
function (pids, next) {
|
||||
Posts.getPostsFields(pids, ['uid'], next);
|
||||
},
|
||||
function(postData, next) {
|
||||
postData = postData.map(function(post) {
|
||||
function (postData, next) {
|
||||
postData = postData.map(function (post) {
|
||||
return post && post.uid;
|
||||
}).filter(function(value, index, array) {
|
||||
}).filter(function (value, index, array) {
|
||||
return value && array.indexOf(value) === index;
|
||||
});
|
||||
next(null, postData);
|
||||
|
||||
@@ -12,9 +12,9 @@ var categories = require('../categories');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getPostSummaryByPids = function(pids, uid, options, callback) {
|
||||
Posts.getPostSummaryByPids = function (pids, uid, options, callback) {
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
@@ -27,16 +27,16 @@ module.exports = function(Posts) {
|
||||
|
||||
var posts;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
Posts.getPostsFields(pids, fields, next);
|
||||
},
|
||||
function(_posts, next) {
|
||||
function (_posts, next) {
|
||||
posts = _posts.filter(Boolean);
|
||||
|
||||
var uids = [];
|
||||
var topicKeys = [];
|
||||
|
||||
posts.forEach(function(post, i) {
|
||||
posts.forEach(function (post, i) {
|
||||
if (uids.indexOf(posts[i].uid) === -1) {
|
||||
uids.push(posts[i].uid);
|
||||
}
|
||||
@@ -45,20 +45,20 @@ module.exports = function(Posts) {
|
||||
}
|
||||
});
|
||||
async.parallel({
|
||||
users: function(next) {
|
||||
users: function (next) {
|
||||
user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture'], next);
|
||||
},
|
||||
topicsAndCategories: function(next) {
|
||||
topicsAndCategories: function (next) {
|
||||
getTopicAndCategories(topicKeys, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
function (results, next) {
|
||||
results.users = toObject('uid', results.users);
|
||||
results.topics = toObject('tid', results.topicsAndCategories.topics);
|
||||
results.categories = toObject('cid', results.topicsAndCategories.categories);
|
||||
|
||||
posts.forEach(function(post) {
|
||||
posts.forEach(function (post) {
|
||||
// If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest.
|
||||
if (!results.users.hasOwnProperty(post.uid)) {
|
||||
post.uid = 0;
|
||||
@@ -74,23 +74,23 @@ module.exports = function(Posts) {
|
||||
post.timestampISO = utils.toISOString(post.timestamp);
|
||||
});
|
||||
|
||||
posts = posts.filter(function(post) {
|
||||
posts = posts.filter(function (post) {
|
||||
return results.topics[post.tid];
|
||||
});
|
||||
|
||||
parsePosts(posts, options, next);
|
||||
},
|
||||
function(posts, next) {
|
||||
function (posts, next) {
|
||||
plugins.fireHook('filter:post.getPostSummaryByPids', {posts: posts, uid: uid}, next);
|
||||
},
|
||||
function(data, next) {
|
||||
function (data, next) {
|
||||
next(null, data.posts);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
function parsePosts(posts, options, callback) {
|
||||
async.map(posts, function(post, next) {
|
||||
async.map(posts, function (post, next) {
|
||||
if (!post.content || !options.parse) {
|
||||
if (options.stripTags) {
|
||||
post.content = stripTags(post.content);
|
||||
@@ -99,7 +99,7 @@ module.exports = function(Posts) {
|
||||
return next(null, post);
|
||||
}
|
||||
|
||||
Posts.parsePost(post, function(err, post) {
|
||||
Posts.parsePost(post, function (err, post) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -113,22 +113,22 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
function getTopicAndCategories(topicKeys, callback) {
|
||||
db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount', 'mainPid'], function(err, topics) {
|
||||
db.getObjectsFields(topicKeys, ['uid', 'tid', 'title', 'cid', 'slug', 'deleted', 'postcount', 'mainPid'], function (err, topics) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var cids = topics.map(function(topic) {
|
||||
var cids = topics.map(function (topic) {
|
||||
if (topic) {
|
||||
topic.title = validator.escape(String(topic.title));
|
||||
topic.deleted = parseInt(topic.deleted, 10) === 1;
|
||||
}
|
||||
return topic && topic.cid;
|
||||
}).filter(function(topic, index, array) {
|
||||
}).filter(function (topic, index, array) {
|
||||
return topic && array.indexOf(topic) === index;
|
||||
});
|
||||
|
||||
categories.getCategoriesFields(cids, ['cid', 'name', 'icon', 'slug', 'parentCid', 'bgColor', 'color'], function(err, categories) {
|
||||
categories.getCategoriesFields(cids, ['cid', 'name', 'icon', 'slug', 'parentCid', 'bgColor', 'color'], function (err, categories) {
|
||||
callback(err, {topics: topics, categories: categories});
|
||||
});
|
||||
});
|
||||
@@ -136,7 +136,7 @@ module.exports = function(Posts) {
|
||||
|
||||
function toObject(key, data) {
|
||||
var obj = {};
|
||||
for(var i=0; i<data.length; ++i) {
|
||||
for(var i = 0; i < data.length; ++i) {
|
||||
obj[data[i][key]] = data[i];
|
||||
}
|
||||
return obj;
|
||||
|
||||
@@ -5,14 +5,14 @@ var async = require('async');
|
||||
var privileges = require('../privileges');
|
||||
var cache = require('./cache');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
Posts.tools = {};
|
||||
|
||||
Posts.tools.delete = function(uid, pid, callback) {
|
||||
Posts.tools.delete = function (uid, pid, callback) {
|
||||
togglePostDelete(uid, pid, true, callback);
|
||||
};
|
||||
|
||||
Posts.tools.restore = function(uid, pid, callback) {
|
||||
Posts.tools.restore = function (uid, pid, callback) {
|
||||
togglePostDelete(uid, pid, false, callback);
|
||||
};
|
||||
|
||||
@@ -45,7 +45,7 @@ module.exports = function(Posts) {
|
||||
cache.del(pid);
|
||||
Posts.delete(pid, uid, next);
|
||||
} else {
|
||||
Posts.restore(pid, uid, function(err, postData) {
|
||||
Posts.restore(pid, uid, function (err, postData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -56,7 +56,7 @@ module.exports = function(Posts) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
Posts.tools.purge = function(uid, pid, callback) {
|
||||
Posts.tools.purge = function (uid, pid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.posts.canPurge(pid, uid, next);
|
||||
|
||||
@@ -6,46 +6,46 @@ var async = require('async');
|
||||
var topics = require('../topics');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getPostsFromSet = function(set, start, stop, uid, reverse, callback) {
|
||||
Posts.getPostsFromSet = function (set, start, stop, uid, reverse, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
Posts.getPidsFromSet(set, start, stop, reverse, next);
|
||||
},
|
||||
function(pids, next) {
|
||||
function (pids, next) {
|
||||
Posts.getPostsByPids(pids, uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.isMain = function(pid, callback) {
|
||||
Posts.isMain = function (pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
Posts.getPostField(pid, 'tid', next);
|
||||
},
|
||||
function(tid, next) {
|
||||
function (tid, next) {
|
||||
topics.getTopicField(tid, 'mainPid', next);
|
||||
},
|
||||
function(mainPid, next) {
|
||||
function (mainPid, next) {
|
||||
next(null, parseInt(pid, 10) === parseInt(mainPid, 10));
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.getTopicFields = function(pid, fields, callback) {
|
||||
Posts.getTopicFields = function (pid, fields, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
Posts.getPostField(pid, 'tid', next);
|
||||
},
|
||||
function(tid, next) {
|
||||
function (tid, next) {
|
||||
topics.getTopicFields(tid, fields, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
Posts.generatePostPath = function (pid, uid, callback) {
|
||||
Posts.generatePostPaths([pid], uid, function(err, paths) {
|
||||
Posts.generatePostPaths([pid], uid, function (err, paths) {
|
||||
callback(err, Array.isArray(paths) && paths.length ? paths[0] : null);
|
||||
});
|
||||
};
|
||||
@@ -57,11 +57,11 @@ module.exports = function(Posts) {
|
||||
},
|
||||
function (postData, next) {
|
||||
async.parallel({
|
||||
indices: function(next) {
|
||||
indices: function (next) {
|
||||
Posts.getPostIndices(postData, uid, next);
|
||||
},
|
||||
topics: function(next) {
|
||||
var tids = postData.map(function(post) {
|
||||
topics: function (next) {
|
||||
var tids = postData.map(function (post) {
|
||||
return post ? post.tid : null;
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ module.exports = function(Posts) {
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
var paths = pids.map(function(pid, index) {
|
||||
var paths = pids.map(function (pid, index) {
|
||||
var slug = results.topics[index] ? results.topics[index].slug : null;
|
||||
var postIndex = utils.isNumber(results.indices[index]) ? parseInt(results.indices[index], 10) + 1 : null;
|
||||
|
||||
|
||||
@@ -8,30 +8,30 @@ var groups = require('../groups');
|
||||
var meta = require('../meta');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getUserInfoForPosts = function(uids, uid, callback) {
|
||||
Posts.getUserInfoForPosts = function (uids, uid, callback) {
|
||||
var groupsMap = {};
|
||||
var userData;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
function (next) {
|
||||
user.getUsersFields(uids, ['uid', 'username', 'fullname', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned', 'status', 'lastonline', 'groupTitle'], next);
|
||||
},
|
||||
function(_userData, next) {
|
||||
function (_userData, next) {
|
||||
userData = _userData;
|
||||
var groupTitles = userData.map(function(userData) {
|
||||
var groupTitles = userData.map(function (userData) {
|
||||
return userData && userData.groupTitle;
|
||||
}).filter(function(groupTitle, index, array) {
|
||||
}).filter(function (groupTitle, index, array) {
|
||||
return groupTitle && array.indexOf(groupTitle) === index;
|
||||
});
|
||||
groups.getGroupsData(groupTitles, next);
|
||||
}
|
||||
], function(err, groupsData) {
|
||||
], function (err, groupsData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
groupsData.forEach(function(group) {
|
||||
groupsData.forEach(function (group) {
|
||||
if (group && group.userTitleEnabled) {
|
||||
groupsMap[group.name] = {
|
||||
name: group.name,
|
||||
@@ -43,7 +43,7 @@ module.exports = function(Posts) {
|
||||
}
|
||||
});
|
||||
|
||||
userData.forEach(function(userData) {
|
||||
userData.forEach(function (userData) {
|
||||
userData.uid = userData.uid || 0;
|
||||
userData.username = userData.username || '[[global:guest]]';
|
||||
userData.userslug = userData.userslug || '';
|
||||
@@ -56,7 +56,7 @@ module.exports = function(Posts) {
|
||||
userData.fullname = validator.escape(String(userData.fullname || ''));
|
||||
});
|
||||
|
||||
async.map(userData, function(userData, next) {
|
||||
async.map(userData, function (userData, next) {
|
||||
async.parallel({
|
||||
isMemberOfGroup: function (next) {
|
||||
if (!userData.groupTitle || !groupsMap[userData.groupTitle]) {
|
||||
@@ -64,17 +64,17 @@ module.exports = function(Posts) {
|
||||
}
|
||||
groups.isMember(userData.uid, userData.groupTitle, next);
|
||||
},
|
||||
signature: function(next) {
|
||||
signature: function (next) {
|
||||
if (!userData.signature || parseInt(meta.config.disableSignatures, 10) === 1) {
|
||||
userData.signature = '';
|
||||
return next();
|
||||
}
|
||||
Posts.parseSignature(userData, uid, next);
|
||||
},
|
||||
customProfileInfo: function(next) {
|
||||
customProfileInfo: function (next) {
|
||||
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
@@ -92,17 +92,17 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.isOwner = function(pid, uid, callback) {
|
||||
Posts.isOwner = function (pid, uid, callback) {
|
||||
uid = parseInt(uid, 10);
|
||||
if (Array.isArray(pid)) {
|
||||
if (!uid) {
|
||||
return callback(null, pid.map(function() {return false;}));
|
||||
return callback(null, pid.map(function () {return false;}));
|
||||
}
|
||||
Posts.getPostsFields(pid, ['uid'], function(err, posts) {
|
||||
Posts.getPostsFields(pid, ['uid'], function (err, posts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
posts = posts.map(function(post) {
|
||||
posts = posts.map(function (post) {
|
||||
return post && parseInt(post.uid, 10) === uid;
|
||||
});
|
||||
callback(null, posts);
|
||||
@@ -111,17 +111,17 @@ module.exports = function(Posts) {
|
||||
if (!uid) {
|
||||
return callback(null, false);
|
||||
}
|
||||
Posts.getPostField(pid, 'uid', function(err, author) {
|
||||
Posts.getPostField(pid, 'uid', function (err, author) {
|
||||
callback(err, parseInt(author, 10) === uid);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Posts.isModerator = function(pids, uid, callback) {
|
||||
Posts.isModerator = function (pids, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, pids.map(function() {return false;}));
|
||||
return callback(null, pids.map(function () {return false;}));
|
||||
}
|
||||
Posts.getCidsByPids(pids, function(err, cids) {
|
||||
Posts.getCidsByPids(pids, function (err, cids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ var db = require('../database');
|
||||
var user = require('../user');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function(Posts) {
|
||||
module.exports = function (Posts) {
|
||||
|
||||
var votesInProgress = {};
|
||||
|
||||
Posts.upvote = function(pid, uid, callback) {
|
||||
Posts.upvote = function (pid, uid, callback) {
|
||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||
}
|
||||
@@ -22,13 +22,13 @@ module.exports = function(Posts) {
|
||||
|
||||
putVoteInProgress(pid, uid);
|
||||
|
||||
toggleVote('upvote', pid, uid, function(err, data) {
|
||||
toggleVote('upvote', pid, uid, function (err, data) {
|
||||
clearVoteProgress(pid, uid);
|
||||
callback(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.downvote = function(pid, uid, callback) {
|
||||
Posts.downvote = function (pid, uid, callback) {
|
||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||
}
|
||||
@@ -43,31 +43,31 @@ module.exports = function(Posts) {
|
||||
|
||||
putVoteInProgress(pid, uid);
|
||||
|
||||
toggleVote('downvote', pid, uid, function(err, data) {
|
||||
toggleVote('downvote', pid, uid, function (err, data) {
|
||||
clearVoteProgress(pid, uid);
|
||||
callback(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.unvote = function(pid, uid, callback) {
|
||||
Posts.unvote = function (pid, uid, callback) {
|
||||
if (voteInProgress(pid, uid)) {
|
||||
return callback(new Error('[[error:already-voting-for-this-post]]'));
|
||||
}
|
||||
|
||||
putVoteInProgress(pid, uid);
|
||||
|
||||
unvote(pid, uid, 'unvote', function(err, data) {
|
||||
unvote(pid, uid, 'unvote', function (err, data) {
|
||||
clearVoteProgress(pid, uid);
|
||||
callback(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
Posts.hasVoted = function(pid, uid, callback) {
|
||||
Posts.hasVoted = function (pid, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, {upvoted: false, downvoted: false});
|
||||
}
|
||||
|
||||
db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function(err, hasVoted) {
|
||||
db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function (err, hasVoted) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -76,31 +76,31 @@ module.exports = function(Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getVoteStatusByPostIDs = function(pids, uid, callback) {
|
||||
Posts.getVoteStatusByPostIDs = function (pids, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
var data = pids.map(function() { return false; });
|
||||
var data = pids.map(function () { return false; });
|
||||
return callback(null, {upvotes: data, downvotes: data});
|
||||
}
|
||||
var upvoteSets = [];
|
||||
var downvoteSets = [];
|
||||
|
||||
for (var i=0; i<pids.length; ++i) {
|
||||
for (var i = 0; i < pids.length; ++i) {
|
||||
upvoteSets.push('pid:' + pids[i] + ':upvote');
|
||||
downvoteSets.push('pid:' + pids[i] + ':downvote');
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
upvotes: function(next) {
|
||||
upvotes: function (next) {
|
||||
db.isMemberOfSets(upvoteSets, uid, next);
|
||||
},
|
||||
downvotes: function(next) {
|
||||
downvotes: function (next) {
|
||||
db.isMemberOfSets(downvoteSets, uid, next);
|
||||
}
|
||||
}, callback);
|
||||
};
|
||||
|
||||
Posts.getUpvotedUidsByPids = function(pids, callback) {
|
||||
var sets = pids.map(function(pid) {
|
||||
Posts.getUpvotedUidsByPids = function (pids, callback) {
|
||||
var sets = pids.map(function (pid) {
|
||||
return 'pid:' + pid + ':upvote';
|
||||
});
|
||||
db.getSetsMembers(sets, callback);
|
||||
@@ -125,7 +125,7 @@ module.exports = function(Posts) {
|
||||
}
|
||||
|
||||
function toggleVote(type, pid, uid, callback) {
|
||||
unvote(pid, uid, type, function(err) {
|
||||
unvote(pid, uid, type, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -136,16 +136,16 @@ module.exports = function(Posts) {
|
||||
|
||||
function unvote(pid, uid, command, callback) {
|
||||
async.parallel({
|
||||
owner: function(next) {
|
||||
owner: function (next) {
|
||||
Posts.getPostField(pid, 'uid', next);
|
||||
},
|
||||
voteStatus: function(next) {
|
||||
voteStatus: function (next) {
|
||||
Posts.hasVoted(pid, uid, next);
|
||||
},
|
||||
reputation: function(next) {
|
||||
reputation: function (next) {
|
||||
user.getUserField(uid, 'reputation', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
@@ -221,7 +221,7 @@ module.exports = function(Posts) {
|
||||
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
|
||||
}
|
||||
|
||||
adjustPostVotes(postData, uid, type, unvote, function(err) {
|
||||
adjustPostVotes(postData, uid, type, unvote, function (err) {
|
||||
callback(err, {
|
||||
user: {
|
||||
reputation: newreputation
|
||||
@@ -239,29 +239,29 @@ module.exports = function(Posts) {
|
||||
var notType = (type === 'upvote' ? 'downvote' : 'upvote');
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
function (next) {
|
||||
if (unvote) {
|
||||
db.setRemove('pid:' + postData.pid + ':' + type, uid, next);
|
||||
} else {
|
||||
db.setAdd('pid:' + postData.pid + ':' + type, uid, next);
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
function (next) {
|
||||
db.setRemove('pid:' + postData.pid + ':' + notType, uid, next);
|
||||
}
|
||||
], function(err) {
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
upvotes: function(next) {
|
||||
upvotes: function (next) {
|
||||
db.setCount('pid:' + postData.pid + ':upvote', next);
|
||||
},
|
||||
downvotes: function(next) {
|
||||
downvotes: function (next) {
|
||||
db.setCount('pid:' + postData.pid + ':downvote', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user