Node.js based forum software built for the modern web
closes #755
Baris Soner Usaklif73c81d6c3b0
diff --git a/src/topics.js b/src/topics.jsindex 37a997d6ad..970a3c65aa 100644--- a/src/topics.js+++ b/src/topics.js@@ -134,6 +134,10 @@ var async = require('async'),Topics.reply = function(tid, uid, content, callback) {threadTools.privileges(tid, uid, function(err, privileges) {+ if(err) {+ return callback(err);+ }+if (content) {content = content.trim();}@@ -144,54 +148,68 @@ var async = require('async'),return callback(new Error('no-privileges'));}- posts.create(uid, tid, content, function(err, postData) {+ user.getUserField(uid, 'lastposttime', function(err, lastposttime) {if(err) {- return callback(err, null);- } else if(!postData) {- callback(new Error('reply-error'), null);+ return callback(err);}- posts.getCidByPid(postData.pid, function(err, cid) {+ if(!lastposttime) {+ lastposttime = 0;+ }++ if (Date.now() - lastposttime < meta.config.postDelay * 1000) {+ return callback(new Error('too-many-posts'), null);+ }++ posts.create(uid, tid, content, function(err, postData) {if(err) {- return callback(err, null);+ return callback(err);+ } else if(!postData) {+ callback(new Error('reply-error'), null);}- db.delete('cid:' + cid + ':read_by_uid', function(err) {- Topics.markAsUnreadForAll(tid, function(err) {- if(err) {- return callback(err, null);- }+ posts.getCidByPid(postData.pid, function(err, cid) {+ if(err) {+ return callback(err, null);+ }++ db.delete('cid:' + cid + ':read_by_uid', function(err) {+ Topics.markAsUnreadForAll(tid, function(err) {+ if(err) {+ return callback(err, null);+ }- Topics.markAsRead(tid, uid);- Topics.pushUnreadCount();+ Topics.markAsRead(tid, uid);+ Topics.pushUnreadCount();+ });});});- });- db.getObjectField('tid:lastFeedUpdate', tid, function(err, lastFeedUpdate) {- var now = Date.now();- if(!lastFeedUpdate || parseInt(lastFeedUpdate, 10) < now - 3600000) {- feed.updateTopic(tid);- db.setObjectField('tid:lastFeedUpdate', tid, now);- }- });+ db.getObjectField('tid:lastFeedUpdate', tid, function(err, lastFeedUpdate) {+ var now = Date.now();+ if(!lastFeedUpdate || parseInt(lastFeedUpdate, 10) < now - 3600000) {+ feed.updateTopic(tid);+ db.setObjectField('tid:lastFeedUpdate', tid, now);+ }+ });- feed.updateRecent();+ feed.updateRecent();- threadTools.notifyFollowers(tid, uid);+ threadTools.notifyFollowers(tid, uid);- user.sendPostNotificationToFollowers(uid, tid, postData.pid);+ user.sendPostNotificationToFollowers(uid, tid, postData.pid);- posts.addUserInfoToPost(postData, function(err) {- if(err) {- return callback(err, null);- }+ posts.addUserInfoToPost(postData, function(err) {+ if(err) {+ return callback(err, null);+ }- postData.favourited = false;- postData.display_moderator_tools = true;- postData.relativeTime = new Date(postData.timestamp).toISOString();+ postData.favourited = false;+ postData.display_moderator_tools = true;+ postData.relativeTime = new Date(postData.timestamp).toISOString();- callback(null, postData);+ callback(null, postData);+ });});});});