2017-09-13 16:11:27 +02:00
|
|
|
import Users from 'meteor/vulcan:users';
|
2017-09-22 12:24:15 +02:00
|
|
|
import { addCallback, getSetting, registerSetting } from 'meteor/vulcan:core';
|
2017-09-13 16:11:27 +02:00
|
|
|
import Comments from '../../../modules/comments/index.js';
|
|
|
|
|
2017-09-22 12:24:15 +02:00
|
|
|
registerSetting('forum.commentInterval', 15, 'How long users should wait in between comments (in seconds)');
|
|
|
|
|
2017-09-13 16:11:27 +02:00
|
|
|
function CommentsNewRateLimit (comment, user) {
|
|
|
|
if (!Users.isAdmin(user)) {
|
|
|
|
const timeSinceLastComment = Users.timeSinceLast(user, Comments);
|
2017-09-22 12:24:15 +02:00
|
|
|
const commentInterval = Math.abs(parseInt(getSetting('forum.commentInterval',15)));
|
2017-09-13 16:11:27 +02:00
|
|
|
|
|
|
|
// check that user waits more than 15 seconds between comments
|
|
|
|
if((timeSinceLastComment < commentInterval)) {
|
|
|
|
throw new Error(Utils.encodeIntlError({id: 'comments.rate_limit_error', value: commentInterval-timeSinceLastComment}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return comment;
|
|
|
|
}
|
|
|
|
addCallback('comments.new.validate', CommentsNewRateLimit);
|