v1.18.x
Barış Soner Uşaklı 7 years ago
parent d5d6748c71
commit 6b1af76f08

@ -50,7 +50,7 @@ module.exports = function (Posts) {
}, next); }, next);
}, },
function (next) { function (next) {
user.setUserField(data.uid, 'lastposttime', Date.now(), next); user.setUserField(data.uid, 'lastqueuetime', Date.now(), next);
}, },
function (next) { function (next) {
notifications.create({ notifications.create({
@ -95,8 +95,8 @@ module.exports = function (Posts) {
privileges.categories.can('topics:reply', cid, data.uid, next); privileges.categories.can('topics:reply', cid, data.uid, next);
} }
}, },
isReadyToPost: function (next) { isReadyToQueue: function (next) {
user.isReadyToPost(data.uid, cid, next); user.isReadyToQueue(data.uid, cid, next);
}, },
}, next); }, next);
}, },

@ -7,6 +7,14 @@ var privileges = require('../privileges');
module.exports = function (User) { module.exports = function (User) {
User.isReadyToPost = function (uid, cid, callback) { User.isReadyToPost = function (uid, cid, callback) {
isReady(uid, cid, 'lastposttime', callback);
};
User.isReadyToQueue = function (uid, cid, callback) {
isReady(uid, cid, 'lastqueuetime', callback);
};
function isReady(uid, cid, field, callback) {
if (parseInt(uid, 10) === 0) { if (parseInt(uid, 10) === 0) {
return callback(); return callback();
} }
@ -14,10 +22,7 @@ module.exports = function (User) {
function (next) { function (next) {
async.parallel({ async.parallel({
userData: function (next) { userData: function (next) {
User.getUserFields(uid, ['banned', 'lastposttime', 'joindate', 'email', 'email:confirmed', 'reputation'], next); User.getUserFields(uid, ['uid', 'banned', 'joindate', 'email', 'email:confirmed', 'reputation'].concat([field]), next);
},
exists: function (next) {
db.exists('user:' + uid, next);
}, },
isAdminOrMod: function (next) { isAdminOrMod: function (next) {
privileges.categories.isAdminOrMod(cid, uid, next); privileges.categories.isAdminOrMod(cid, uid, next);
@ -25,7 +30,7 @@ module.exports = function (User) {
}, next); }, next);
}, },
function (results, next) { function (results, next) {
if (!results.exists) { if (!parseInt(results.userData.uid, 10)) {
return next(new Error('[[error:no-user]]')); return next(new Error('[[error:no-user]]'));
} }
@ -48,18 +53,18 @@ module.exports = function (User) {
return next(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]')); return next(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
} }
var lastposttime = userData.lastposttime || 0; var lasttime = userData[field] || 0;
if (parseInt(meta.config.newbiePostDelay, 10) > 0 && parseInt(meta.config.newbiePostDelayThreshold, 10) > parseInt(userData.reputation, 10) && now - parseInt(lastposttime, 10) < parseInt(meta.config.newbiePostDelay, 10) * 1000) { if (parseInt(meta.config.newbiePostDelay, 10) > 0 && parseInt(meta.config.newbiePostDelayThreshold, 10) > parseInt(userData.reputation, 10) && now - parseInt(lasttime, 10) < parseInt(meta.config.newbiePostDelay, 10) * 1000) {
return next(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]')); return next(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
} else if (now - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) { } else if (now - parseInt(lasttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
return next(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]')); return next(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
} }
next(); next();
}, },
], callback); ], callback);
}; }
User.onNewPostMade = function (postData, callback) { User.onNewPostMade = function (postData, callback) {
async.series([ async.series([

@ -726,7 +726,6 @@ describe('Post\'s', function () {
}); });
}); });
describe('filterPidsByCid', function () { describe('filterPidsByCid', function () {
it('should return pids as is if cid is falsy', function (done) { it('should return pids as is if cid is falsy', function (done) {
posts.filterPidsByCid([1, 2, 3], null, function (err, pids) { posts.filterPidsByCid([1, 2, 3], null, function (err, pids) {
@ -753,6 +752,13 @@ describe('Post\'s', function () {
}); });
}); });
it('should error if user does not exist', function (done) {
user.isReadyToPost(21123123, 1, function (err) {
assert.equal(err.message, '[[error:no-user]]');
done();
});
});
describe('post queue', function () { describe('post queue', function () {
var uid; var uid;
before(function (done) { before(function (done) {

Loading…
Cancel
Save