feat: comments post min delay
This commit is contained in:
		@@ -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)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user