feat: comments post min delay

This commit is contained in:
NGPixel
2020-05-31 15:54:20 -04:00
parent 8a74904731
commit e74605501f
4 changed files with 133 additions and 103 deletions

View File

@@ -4,6 +4,7 @@ const { JSDOM } = require('jsdom')
const createDOMPurify = require('dompurify')
const _ = require('lodash')
const { AkismetClient } = require('akismet-api')
const moment = require('moment')
/* global WIKI */
@@ -106,6 +107,14 @@ module.exports = {
}
}
// -> Check for minimum delay between posts
if (WIKI.data.commentProvider.config.minDelay > 0) {
const lastComment = await WIKI.models.comments.query().select('updatedAt').findOne('authorId', user.id).orderBy('updatedAt', 'desc')
if (lastComment && moment().subtract(WIKI.data.commentProvider.config.minDelay, 'seconds').isBefore(lastComment.updatedAt)) {
throw new Error('Your administrator has set a time limit before you can post another comment. Try again later.')
}
}
// -> Save Comment to DB
const cm = await WIKI.models.comments.query().insert(newComment)