Skip to content

Node.js based forum software built for the modern web

Merge branch 'master' of https://github.com/designcreateplay/NodeBB

psychobunny6db259cf3f6b
diff --cc src/posts.js
index 6b93fda730,23d84c2696..07c9e1884c
--- a/src/posts.js
+++ b/src/posts.js
@@@ -140,63 -127,73 +140,73 @@@ marked.setOptions(
return;
}
- Posts.create(uid, tid, content, function(pid) {
- if (pid > 0) {
- RDB.rpush('tid:' + tid + ':posts', pid);
-
- RDB.del('tid:' + tid + ':read_by_uid'); // let everybody know there is an unread post
- Posts.get_cid_by_pid(pid, function(cid) {
- RDB.del('cid:' + cid + ':read_by_uid');
- });
-
- topics.get_cid_by_tid(tid, function(cid) {
- RDB.zadd('categories:recent_posts:cid:' + cid, (new Date()).getTime(), pid);
- });
-
-
- // Re-add the poster, so he/she does not get an "unread" flag on this topic
- topics.markAsRead(tid, uid);
- // this will duplicate once we enter the thread, which is where we should be going
- user.getUserField(uid, 'lastposttime', function(lastposttime) {
++ user.getUserField(uid, 'lastposttime', function(lastposttime) {
+ if(new Date().getTime() - lastposttime < config.post_delay) {
socket.emit('event:alert', {
- title: 'Reply Successful',
- message: 'You have successfully replied. Click here to view your reply.',
- type: 'notify',
+ title: 'Too many posts!',
+ message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.',
+ type: 'error',
timeout: 2000
});
+ return;
+ }
- user.getUserFields(uid, ['username','reputation','picture','signature'], function(data) {
-
- var timestamp = new Date().getTime();
-
- io.sockets.in('topic_' + tid).emit('event:new_post', {
- 'posts' : [
- {
- 'pid' : pid,
- 'content' : marked(content || ''),
- 'uid' : uid,
- 'username' : data.username || 'anonymous',
- 'user_rep' : data.reputation || 0,
- 'post_rep' : 0,
- 'gravatar' : data.picture,
- 'signature' : marked(data.signature || ''),
- 'timestamp' : timestamp,
- 'relativeTime': utils.relativeTime(timestamp),
- 'fav_star_class' :'icon-star-empty',
- 'edited-class': 'none',
- 'editor': '',
- }
- ]
+ Posts.create(uid, tid, content, function(pid) {
+ if (pid > 0) {
+ RDB.rpush('tid:' + tid + ':posts', pid);
+
+ RDB.del('tid:' + tid + ':read_by_uid'); // let everybody know there is an unread post
+ Posts.get_cid_by_pid(pid, function(cid) {
+ RDB.del('cid:' + cid + ':read_by_uid');
});
- });
- } else {
- socket.emit('event:alert', {
- title: 'Reply Unsuccessful',
- message: 'Your reply could not be posted at this time. Please try again later.',
- type: 'notify',
- timeout: 2000
- });
- }
+
+ RDB.zadd('topics:recent_posts:tid:' + tid, (new Date()).getTime(), pid);
+
+ // Re-add the poster, so he/she does not get an "unread" flag on this topic
+ topics.markAsRead(tid, uid);
+ // this will duplicate once we enter the thread, which is where we should be going
+
+ socket.emit('event:alert', {
+ title: 'Reply Successful',
+ message: 'You have successfully replied. Click here to view your reply.',
+ type: 'notify',
+ timeout: 2000
+ });
+
+ user.getUserFields(uid, ['username','reputation','picture','signature'], function(data) {
+
+ var timestamp = new Date().getTime();
+
+ io.sockets.in('topic_' + tid).emit('event:new_post', {
+ 'posts' : [
+ {
+ 'pid' : pid,
+ 'content' : marked(content || ''),
+ 'uid' : uid,
+ 'username' : data.username || 'anonymous',
+ 'user_rep' : data.reputation || 0,
+ 'post_rep' : 0,
+ 'gravatar' : data.picture,
+ 'signature' : marked(data.signature || ''),
+ 'timestamp' : timestamp,
+ 'relativeTime': utils.relativeTime(timestamp),
+ 'fav_star_class' :'icon-star-empty',
+ 'edited-class': 'none',
+ 'editor': '',
+ }
+ ]
+ });
+ });
+ } else {
+ socket.emit('event:alert', {
+ title: 'Reply Unsuccessful',
+ message: 'Your reply could not be posted at this time. Please try again later.',
+ type: 'notify',
+ timeout: 2000
+ });
+ }
+ });
});
};