mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-05 03:51:26 +01:00
Merge branch 'master' into develop
This commit is contained in:
@@ -6,7 +6,6 @@ var db = require('../database');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.bookmark = function (pid, uid, callback) {
|
||||
toggleBookmark('bookmark', pid, uid, callback);
|
||||
};
|
||||
@@ -30,7 +29,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
hasBookmarked: function (next) {
|
||||
Posts.hasBookmarked(pid, uid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -61,7 +60,7 @@ module.exports = function (Posts) {
|
||||
function (count, next) {
|
||||
results.postData.bookmarks = count;
|
||||
Posts.setPostField(pid, 'bookmarks', count, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -73,12 +72,12 @@ module.exports = function (Posts) {
|
||||
pid: pid,
|
||||
uid: uid,
|
||||
owner: results.owner,
|
||||
current: current
|
||||
current: current,
|
||||
});
|
||||
|
||||
callback(null, {
|
||||
post: results.postData,
|
||||
isBookmarked: isBookmarking
|
||||
isBookmarked: isBookmarking,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var LRU = require('lru-cache');
|
||||
var meta = require('../meta');
|
||||
|
||||
var cache = LRU({
|
||||
max: parseInt(meta.config.postCacheSize, 10) || 1048576,
|
||||
length: function (n) { return n.length; },
|
||||
maxAge: 1000 * 60 * 60
|
||||
maxAge: 1000 * 60 * 60,
|
||||
});
|
||||
|
||||
module.exports = cache;
|
||||
module.exports = cache;
|
||||
|
||||
@@ -8,7 +8,6 @@ var db = require('../database');
|
||||
var topics = require('../topics');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getCidByPid = function (pid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -16,7 +15,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (tid, next) {
|
||||
topics.getTopicField(tid, 'cid', next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -49,7 +48,7 @@ module.exports = function (Posts) {
|
||||
return map[post.tid];
|
||||
});
|
||||
next(null, cids);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -82,4 +81,4 @@ module.exports = function (Posts) {
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -12,7 +12,6 @@ var categories = require('../categories');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.create = function (data, callback) {
|
||||
// This is an internal method, consider using Topics.reply instead
|
||||
var uid = data.uid;
|
||||
@@ -36,14 +35,13 @@ module.exports = function (Posts) {
|
||||
db.incrObjectField('global', 'nextPid', next);
|
||||
},
|
||||
function (pid, next) {
|
||||
|
||||
postData = {
|
||||
'pid': pid,
|
||||
'uid': uid,
|
||||
'tid': tid,
|
||||
'content': content,
|
||||
'timestamp': timestamp,
|
||||
'deleted': 0
|
||||
pid: pid,
|
||||
uid: uid,
|
||||
tid: tid,
|
||||
content: content,
|
||||
timestamp: timestamp,
|
||||
deleted: 0,
|
||||
};
|
||||
|
||||
if (data.toPid) {
|
||||
@@ -61,7 +59,7 @@ module.exports = function (Posts) {
|
||||
plugins.fireHook('filter:post.save', postData, next);
|
||||
},
|
||||
function (postData, next) {
|
||||
plugins.fireHook('filter:post.create', {post: postData, data: data}, next);
|
||||
plugins.fireHook('filter:post.create', { post: postData, data: data }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
postData = data.post;
|
||||
@@ -93,12 +91,12 @@ module.exports = function (Posts) {
|
||||
}
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetAdd, 'pid:' + postData.toPid + ':replies', timestamp, postData.pid),
|
||||
async.apply(db.incrObjectField, 'post:' + postData.toPid, 'replies')
|
||||
async.apply(db.incrObjectField, 'post:' + postData.toPid, 'replies'),
|
||||
], next);
|
||||
},
|
||||
function (next) {
|
||||
db.incrObjectField('global', 'postCount', next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -110,9 +108,8 @@ module.exports = function (Posts) {
|
||||
postData.isMain = isMain;
|
||||
plugins.fireHook('action:post.save', {post: _.clone(postData)});
|
||||
next(null, postData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -11,15 +11,14 @@ var plugins = require('../plugins');
|
||||
var flags = require('../flags');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.delete = function (pid, uid, callback) {
|
||||
var postData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:post.delete', {pid: pid, uid: uid}, next);
|
||||
plugins.fireHook('filter:post.delete', { pid: pid, uid: uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
Posts.setPostFields(pid, {deleted: 1, deleterUid: uid}, next);
|
||||
Posts.setPostFields(pid, { deleted: 1, deleterUid: uid }, next);
|
||||
},
|
||||
function (next) {
|
||||
Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'timestamp'], next);
|
||||
@@ -39,13 +38,13 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (next) {
|
||||
topics.updateTeaser(postData.tid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
},
|
||||
function (results, next) {
|
||||
plugins.fireHook('action:post.delete', {post: _.clone(postData), uid: uid});
|
||||
plugins.fireHook('action:post.delete', { post: _.clone(postData), uid: uid });
|
||||
next(null, postData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -53,10 +52,10 @@ module.exports = function (Posts) {
|
||||
var postData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:post.restore', {pid: pid, uid: uid}, next);
|
||||
plugins.fireHook('filter:post.restore', { pid: pid, uid: uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
Posts.setPostFields(pid, {deleted: 0, deleterUid: 0}, next);
|
||||
Posts.setPostFields(pid, { deleted: 0, deleterUid: 0 }, next);
|
||||
},
|
||||
function (next) {
|
||||
Posts.getPostFields(pid, ['pid', 'tid', 'uid', 'content', 'timestamp'], next);
|
||||
@@ -76,13 +75,13 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (next) {
|
||||
topics.updateTeaser(postData.tid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
},
|
||||
function (results, next) {
|
||||
plugins.fireHook('action:post.restore', {post: _.clone(postData), uid: uid});
|
||||
plugins.fireHook('action:post.restore', { post: _.clone(postData), uid: uid });
|
||||
next(null, postData);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -111,7 +110,7 @@ module.exports = function (Posts) {
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -124,7 +123,7 @@ module.exports = function (Posts) {
|
||||
if (!exists) {
|
||||
return callback();
|
||||
}
|
||||
plugins.fireHook('filter:post.purge', {pid: pid, uid: uid}, next);
|
||||
plugins.fireHook('filter:post.purge', { pid: pid, uid: uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
async.parallel([
|
||||
@@ -145,7 +144,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
next(err);
|
||||
});
|
||||
@@ -154,9 +153,9 @@ module.exports = function (Posts) {
|
||||
Posts.getPostData(pid, next);
|
||||
},
|
||||
function (postData, next) {
|
||||
plugins.fireHook('action:post.purge', {post: postData, uid: uid});
|
||||
plugins.fireHook('action:post.purge', { post: postData, uid: uid });
|
||||
db.delete('post:' + pid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -171,7 +170,7 @@ module.exports = function (Posts) {
|
||||
db.sortedSetsRemove([
|
||||
'tid:' + postData.tid + ':posts',
|
||||
'tid:' + postData.tid + ':posts:votes',
|
||||
'uid:' + postData.uid + ':posts'
|
||||
'uid:' + postData.uid + ':posts',
|
||||
], pid, next);
|
||||
},
|
||||
function (next) {
|
||||
@@ -205,9 +204,9 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (next) {
|
||||
notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + pid + ':uid:' + postData.uid, next);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
@@ -254,7 +253,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
downvoters: function (next) {
|
||||
db.getSetMembers('pid:' + pid + ':downvote', next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -277,7 +276,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (next) {
|
||||
db.deleteAll(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
}
|
||||
@@ -292,10 +291,8 @@ module.exports = function (Posts) {
|
||||
}
|
||||
async.parallel([
|
||||
async.apply(db.sortedSetRemove, 'pid:' + toPid + ':replies', pid),
|
||||
async.apply(db.decrObjectField, 'post:' + toPid, 'replies')
|
||||
async.apply(db.decrObjectField, 'post:' + toPid, 'replies'),
|
||||
], callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@ var pubsub = require('../pubsub');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
pubsub.on('post:edit', function (pid) {
|
||||
cache.del(pid);
|
||||
});
|
||||
@@ -45,7 +44,7 @@ module.exports = function (Posts) {
|
||||
if (data.handle) {
|
||||
postData.handle = data.handle;
|
||||
}
|
||||
plugins.fireHook('filter:post.edit', {req: data.req, post: postData, data: data, uid: data.uid}, next);
|
||||
plugins.fireHook('filter:post.edit', { req: data.req, post: postData, data: data, uid: data.uid }, next);
|
||||
},
|
||||
function (result, next) {
|
||||
postData = result.post;
|
||||
@@ -58,7 +57,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
topic: function (next) {
|
||||
editMainPost(data, postData, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (_results, next) {
|
||||
@@ -76,7 +75,7 @@ module.exports = function (Posts) {
|
||||
function (postData, next) {
|
||||
results.post = postData;
|
||||
next(null, results);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -90,7 +89,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
isMain: function (next) {
|
||||
Posts.isMain(data.pid, next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -101,7 +100,7 @@ module.exports = function (Posts) {
|
||||
tid: tid,
|
||||
cid: results.topic.cid,
|
||||
isMainPost: false,
|
||||
renamed: false
|
||||
renamed: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -109,7 +108,7 @@ module.exports = function (Posts) {
|
||||
tid: tid,
|
||||
cid: results.topic.cid,
|
||||
uid: postData.uid,
|
||||
mainPid: data.pid
|
||||
mainPid: data.pid,
|
||||
};
|
||||
|
||||
if (title) {
|
||||
@@ -123,7 +122,7 @@ module.exports = function (Posts) {
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:topic.edit', {req: data.req, topic: topicData, data: data}, next);
|
||||
plugins.fireHook('filter:topic.edit', { req: data.req, topic: topicData, data: data }, next);
|
||||
},
|
||||
function (results, next) {
|
||||
db.setObject('topic:' + tid, results.topic, next);
|
||||
@@ -147,12 +146,10 @@ module.exports = function (Posts) {
|
||||
slug: topicData.slug,
|
||||
isMainPost: true,
|
||||
renamed: title !== results.topic.title,
|
||||
tags: tags
|
||||
tags: tags,
|
||||
});
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -13,7 +13,6 @@ var translator = require('../../public/src/modules/translator');
|
||||
var urlRegex = /href="([^"]+)"/g;
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.parsePost = function (postData, callback) {
|
||||
postData.content = postData.content || '';
|
||||
|
||||
@@ -27,7 +26,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);
|
||||
}
|
||||
@@ -44,14 +43,16 @@ module.exports = function (Posts) {
|
||||
|
||||
Posts.parseSignature = function (userData, uid, callback) {
|
||||
userData.signature = sanitizeSignature(userData.signature || '');
|
||||
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
||||
plugins.fireHook('filter:parse.signature', { userData: userData, uid: uid }, callback);
|
||||
};
|
||||
|
||||
Posts.relativeToAbsolute = function (content) {
|
||||
// Turns relative links in post body to absolute urls
|
||||
var parsed, current, absolute;
|
||||
var parsed;
|
||||
var current = urlRegex.exec(content);
|
||||
var absolute;
|
||||
|
||||
while ((current = urlRegex.exec(content)) !== null) {
|
||||
while (current !== null) {
|
||||
if (current[1]) {
|
||||
try {
|
||||
parsed = url.parse(current[1]);
|
||||
@@ -66,18 +67,19 @@ module.exports = function (Posts) {
|
||||
|
||||
content = content.slice(0, current.index + 6) + absolute + content.slice(current.index + 6 + current[1].length);
|
||||
}
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
winston.verbose(err.messsage);
|
||||
}
|
||||
}
|
||||
current = urlRegex.exec(content);
|
||||
}
|
||||
|
||||
return content;
|
||||
};
|
||||
|
||||
function sanitizeSignature(signature) {
|
||||
var string = S(signature),
|
||||
tagsToStrip = [];
|
||||
var string = S(signature);
|
||||
var tagsToStrip = [];
|
||||
|
||||
if (parseInt(meta.config['signatures:disableLinks'], 10) === 1) {
|
||||
tagsToStrip.push('a');
|
||||
|
||||
@@ -9,7 +9,7 @@ module.exports = function (Posts) {
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000
|
||||
month: 2592000000,
|
||||
};
|
||||
|
||||
Posts.getRecentPosts = function (uid, start, stop, term, callback) {
|
||||
@@ -28,8 +28,8 @@ module.exports = function (Posts) {
|
||||
privileges.posts.filter('read', pids, uid, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
Posts.getPostSummaryByPids(pids, uid, {stripTags: true}, next);
|
||||
}
|
||||
Posts.getPostSummaryByPids(pids, uid, { stripTags: true }, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ module.exports = function (Posts) {
|
||||
return uid && array.indexOf(uid) === index;
|
||||
});
|
||||
next(null, uids);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -13,7 +13,6 @@ var utils = require('../../public/src/utils');
|
||||
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getPostSummaryByPids = function (pids, uid, options, callback) {
|
||||
if (!Array.isArray(pids) || !pids.length) {
|
||||
return callback(null, []);
|
||||
@@ -50,7 +49,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
topicsAndCategories: function (next) {
|
||||
getTopicAndCategories(topicKeys, next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -81,11 +80,11 @@ module.exports = function (Posts) {
|
||||
parsePosts(posts, options, next);
|
||||
},
|
||||
function (posts, next) {
|
||||
plugins.fireHook('filter:post.getPostSummaryByPids', {posts: posts, uid: uid}, next);
|
||||
plugins.fireHook('filter:post.getPostSummaryByPids', { posts: posts, uid: uid }, next);
|
||||
},
|
||||
function (data, next) {
|
||||
next(null, data.posts);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -129,14 +128,14 @@ module.exports = function (Posts) {
|
||||
});
|
||||
|
||||
categories.getCategoriesFields(cids, ['cid', 'name', 'icon', 'slug', 'parentCid', 'bgColor', 'color'], function (err, categories) {
|
||||
callback(err, {topics: topics, categories: categories});
|
||||
callback(err, { topics: topics, categories: categories });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function toObject(key, data) {
|
||||
var obj = {};
|
||||
for(var i = 0; i < data.length; ++i) {
|
||||
for (var i = 0; i < data.length; i += 1) {
|
||||
obj[data[i][key]] = data[i];
|
||||
}
|
||||
return obj;
|
||||
|
||||
@@ -30,7 +30,7 @@ module.exports = function (Posts) {
|
||||
function (deleted, next) {
|
||||
if (parseInt(deleted, 10) === 1 && isDelete) {
|
||||
return next(new Error('[[error:post-already-deleted]]'));
|
||||
} else if(parseInt(deleted, 10) !== 1 && !isDelete) {
|
||||
} else if (parseInt(deleted, 10) !== 1 && !isDelete) {
|
||||
return next(new Error('[[error:post-already-restored]]'));
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ module.exports = function (Posts) {
|
||||
Posts.parsePost(postData, next);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
@@ -67,9 +67,8 @@ module.exports = function (Posts) {
|
||||
}
|
||||
cache.del(pid);
|
||||
Posts.purge(pid, uid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ var topics = require('../topics');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getPostsFromSet = function (set, start, stop, uid, reverse, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -15,7 +14,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (pids, next) {
|
||||
Posts.getPostsByPids(pids, uid, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -29,7 +28,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (mainPid, next) {
|
||||
next(null, parseInt(pid, 10) === parseInt(mainPid, 10));
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -40,7 +39,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (tid, next) {
|
||||
topics.getTopicFields(tid, fields, next);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -66,7 +65,7 @@ module.exports = function (Posts) {
|
||||
});
|
||||
|
||||
topics.getTopicsFields(tids, ['slug'], next);
|
||||
}
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -81,8 +80,7 @@ module.exports = function (Posts) {
|
||||
});
|
||||
|
||||
next(null, paths);
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -9,7 +9,6 @@ var meta = require('../meta');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
Posts.getUserInfoForPosts = function (uids, uid, callback) {
|
||||
var groupsMap = {};
|
||||
var userData;
|
||||
@@ -25,7 +24,7 @@ module.exports = function (Posts) {
|
||||
return groupTitle && array.indexOf(groupTitle) === index;
|
||||
});
|
||||
groups.getGroupsData(groupTitles, next);
|
||||
}
|
||||
},
|
||||
], function (err, groupsData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -38,7 +37,7 @@ module.exports = function (Posts) {
|
||||
slug: group.slug,
|
||||
labelColor: group.labelColor,
|
||||
icon: group.icon,
|
||||
userTitle: group.userTitle
|
||||
userTitle: group.userTitle,
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -72,8 +71,8 @@ module.exports = function (Posts) {
|
||||
Posts.parseSignature(userData, uid, next);
|
||||
},
|
||||
customProfileInfo: function (next) {
|
||||
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next);
|
||||
}
|
||||
plugins.fireHook('filter:posts.custom_profile_info', { profile: [], uid: userData.uid }, next);
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@@ -95,7 +94,7 @@ module.exports = function (Posts) {
|
||||
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) {
|
||||
if (err) {
|
||||
@@ -118,7 +117,7 @@ module.exports = function (Posts) {
|
||||
|
||||
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) {
|
||||
if (err) {
|
||||
@@ -127,4 +126,4 @@ module.exports = function (Posts) {
|
||||
user.isModerator(uid, cids, callback);
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@ var user = require('../user');
|
||||
var plugins = require('../plugins');
|
||||
|
||||
module.exports = function (Posts) {
|
||||
|
||||
var votesInProgress = {};
|
||||
|
||||
Posts.upvote = function (pid, uid, callback) {
|
||||
@@ -64,7 +63,7 @@ module.exports = function (Posts) {
|
||||
|
||||
Posts.hasVoted = function (pid, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
return callback(null, {upvoted: false, downvoted: false});
|
||||
return callback(null, { upvoted: false, downvoted: false });
|
||||
}
|
||||
|
||||
db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function (err, hasVoted) {
|
||||
@@ -72,19 +71,19 @@ module.exports = function (Posts) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
callback (null, {upvoted: hasVoted[0], downvoted: hasVoted[1]});
|
||||
callback(null, { upvoted: hasVoted[0], downvoted: hasVoted[1] });
|
||||
});
|
||||
};
|
||||
|
||||
Posts.getVoteStatusByPostIDs = function (pids, uid, callback) {
|
||||
if (!parseInt(uid, 10)) {
|
||||
var data = pids.map(function () { return false; });
|
||||
return callback(null, {upvotes: data, downvotes: data});
|
||||
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 += 1) {
|
||||
upvoteSets.push('pid:' + pids[i] + ':upvote');
|
||||
downvoteSets.push('pid:' + pids[i] + ':downvote');
|
||||
}
|
||||
@@ -95,7 +94,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
downvotes: function (next) {
|
||||
db.isMemberOfSets(downvoteSets, uid, next);
|
||||
}
|
||||
},
|
||||
}, callback);
|
||||
};
|
||||
|
||||
@@ -144,7 +143,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
reputation: function (next) {
|
||||
user.getUserField(uid, 'reputation', next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -154,15 +153,15 @@ module.exports = function (Posts) {
|
||||
return callback(new Error('self-vote'));
|
||||
}
|
||||
|
||||
if (command === 'downvote' && parseInt(results.reputation) < parseInt(meta.config['privileges:downvote'], 10)) {
|
||||
if (command === 'downvote' && parseInt(results.reputation, 10) < parseInt(meta.config['privileges:downvote'], 10)) {
|
||||
return callback(new Error('[[error:not-enough-reputation-to-downvote]]'));
|
||||
}
|
||||
|
||||
var voteStatus = results.voteStatus,
|
||||
hook,
|
||||
current = voteStatus.upvoted ? 'upvote' : 'downvote';
|
||||
var voteStatus = results.voteStatus;
|
||||
var hook;
|
||||
var current = voteStatus.upvoted ? 'upvote' : 'downvote';
|
||||
|
||||
if (voteStatus.upvoted && command === 'downvote' || voteStatus.downvoted && command === 'upvote') { // e.g. User *has* upvoted, and clicks downvote
|
||||
if ((voteStatus.upvoted && command === 'downvote') || (voteStatus.downvoted && command === 'upvote')) { // e.g. User *has* upvoted, and clicks downvote
|
||||
hook = command;
|
||||
} else if (voteStatus.upvoted || voteStatus.downvoted) { // e.g. User *has* upvoted, clicks upvote (so we "unvote")
|
||||
hook = 'unvote';
|
||||
@@ -175,7 +174,7 @@ module.exports = function (Posts) {
|
||||
pid: pid,
|
||||
uid: uid,
|
||||
owner: results.owner,
|
||||
current: current
|
||||
current: current,
|
||||
});
|
||||
|
||||
if (!voteStatus || (!voteStatus.upvoted && !voteStatus.downvoted)) {
|
||||
@@ -224,11 +223,11 @@ module.exports = function (Posts) {
|
||||
adjustPostVotes(postData, uid, type, unvote, function (err) {
|
||||
callback(err, {
|
||||
user: {
|
||||
reputation: newreputation
|
||||
reputation: newreputation,
|
||||
},
|
||||
post: postData,
|
||||
upvote: type === 'upvote' && !unvote,
|
||||
downvote: type === 'downvote' && !unvote
|
||||
downvote: type === 'downvote' && !unvote,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -248,7 +247,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
function (next) {
|
||||
db.setRemove('pid:' + postData.pid + ':' + notType, uid, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -260,7 +259,7 @@ module.exports = function (Posts) {
|
||||
},
|
||||
downvotes: function (next) {
|
||||
db.setCount('pid:' + postData.pid + ':downvote', next);
|
||||
}
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
Reference in New Issue
Block a user