mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
post every x seconds added it x to config
This commit is contained in:
@@ -59,7 +59,8 @@ var config = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"show_motd": true,
|
"show_motd": true,
|
||||||
"motd": undefined
|
"motd": undefined,
|
||||||
|
"post_delay" : 10000
|
||||||
}
|
}
|
||||||
|
|
||||||
config.url = config.base_url + (config.use_port ? ':' + config.port : '') + '/';
|
config.url = config.base_url + (config.use_port ? ':' + config.port : '') + '/';
|
||||||
|
|||||||
117
src/posts.js
117
src/posts.js
@@ -127,60 +127,73 @@ marked.setOptions({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.create(uid, tid, content, function(pid) {
|
user.getUserField(uid, 'lastposttime', function(lastposttime) {
|
||||||
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');
|
|
||||||
});
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
if(new Date().getTime() - lastposttime < config.post_delay) {
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
title: 'Reply Successful',
|
title: 'Too many posts!',
|
||||||
message: 'You have successfully replied. Click here to view your reply.',
|
message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.',
|
||||||
type: 'notify',
|
type: 'error',
|
||||||
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
|
timeout: 2000
|
||||||
});
|
});
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -193,11 +206,12 @@ marked.setOptions({
|
|||||||
if (!locked || locked === '0') {
|
if (!locked || locked === '0') {
|
||||||
RDB.incr('global:next_post_id', function(err, pid) {
|
RDB.incr('global:next_post_id', function(err, pid) {
|
||||||
RDB.handle(err);
|
RDB.handle(err);
|
||||||
|
|
||||||
|
var timestamp = new Date().getTime();
|
||||||
// Posts Info
|
// Posts Info
|
||||||
RDB.set('pid:' + pid + ':content', content);
|
RDB.set('pid:' + pid + ':content', content);
|
||||||
RDB.set('pid:' + pid + ':uid', uid);
|
RDB.set('pid:' + pid + ':uid', uid);
|
||||||
RDB.set('pid:' + pid + ':timestamp', new Date().getTime());
|
RDB.set('pid:' + pid + ':timestamp', timestamp);
|
||||||
RDB.set('pid:' + pid + ':rep', 0);
|
RDB.set('pid:' + pid + ':rep', 0);
|
||||||
RDB.set('pid:' + pid + ':tid', tid);
|
RDB.set('pid:' + pid + ':tid', tid);
|
||||||
|
|
||||||
@@ -225,6 +239,7 @@ marked.setOptions({
|
|||||||
RDB.lpush('uid:' + uid + ':posts', pid);
|
RDB.lpush('uid:' + uid + ':posts', pid);
|
||||||
|
|
||||||
user.incrementUserFieldBy(uid, 'postcount', 1);
|
user.incrementUserFieldBy(uid, 'postcount', 1);
|
||||||
|
user.setUserField(uid, 'lastposttime', timestamp);
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
callback(pid);
|
callback(pid);
|
||||||
|
|||||||
125
src/topics.js
125
src/topics.js
@@ -295,68 +295,81 @@ marked.setOptions({
|
|||||||
return; // for now, until anon code is written.
|
return; // for now, until anon code is written.
|
||||||
}
|
}
|
||||||
|
|
||||||
RDB.incr('global:next_topic_id', function(err, tid) {
|
user.getUserField(uid, 'lastposttime', function(lastposttime) {
|
||||||
RDB.handle(err);
|
|
||||||
|
|
||||||
// Global Topics
|
if(new Date().getTime() - lastposttime < config.post_delay) {
|
||||||
if (uid == null) uid = 0;
|
socket.emit('event:alert', {
|
||||||
if (uid !== null) {
|
title: 'Too many posts!',
|
||||||
RDB.sadd('topics:tid', tid);
|
message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.',
|
||||||
} else {
|
type: 'error',
|
||||||
// need to add some unique key sent by client so we can update this with the real uid later
|
timeout: 2000
|
||||||
RDB.lpush('topics:queued:tid', tid);
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var slug = tid + '/' + utils.slugify(title);
|
RDB.incr('global:next_topic_id', function(err, tid) {
|
||||||
|
RDB.handle(err);
|
||||||
|
|
||||||
// Topic Info
|
// Global Topics
|
||||||
RDB.set('tid:' + tid + ':title', title);
|
if (uid == null) uid = 0;
|
||||||
RDB.set('tid:' + tid + ':uid', uid);
|
if (uid !== null) {
|
||||||
RDB.set('tid:' + tid + ':slug', slug);
|
RDB.sadd('topics:tid', tid);
|
||||||
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
|
} else {
|
||||||
|
// need to add some unique key sent by client so we can update this with the real uid later
|
||||||
|
RDB.lpush('topics:queued:tid', tid);
|
||||||
RDB.set('topic:slug:' + slug + ':tid', tid);
|
|
||||||
|
|
||||||
// Posts
|
|
||||||
posts.create(uid, tid, content, function(pid) {
|
|
||||||
if (pid > 0) {
|
|
||||||
RDB.lpush('tid:' + tid + ':posts', pid);
|
|
||||||
|
|
||||||
// Notify any users looking at the category that a new topic has arrived
|
|
||||||
Topics.get_topic(tid, uid, function(topicData) {
|
|
||||||
io.sockets.in('category_' + category_id).emit('event:new_topic', topicData);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var slug = tid + '/' + utils.slugify(title);
|
||||||
|
|
||||||
|
// Topic Info
|
||||||
|
RDB.set('tid:' + tid + ':title', title);
|
||||||
|
RDB.set('tid:' + tid + ':uid', uid);
|
||||||
|
RDB.set('tid:' + tid + ':slug', slug);
|
||||||
|
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
|
||||||
|
|
||||||
|
|
||||||
|
RDB.set('topic:slug:' + slug + ':tid', tid);
|
||||||
|
|
||||||
|
// Posts
|
||||||
|
posts.create(uid, tid, content, function(pid) {
|
||||||
|
if (pid > 0) {
|
||||||
|
RDB.lpush('tid:' + tid + ':posts', pid);
|
||||||
|
|
||||||
|
// Notify any users looking at the category that a new topic has arrived
|
||||||
|
Topics.get_topic(tid, uid, function(topicData) {
|
||||||
|
io.sockets.in('category_' + category_id).emit('event:new_topic', topicData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Topics.markAsRead(tid, uid);
|
||||||
|
|
||||||
|
// User Details - move this out later
|
||||||
|
RDB.lpush('uid:' + uid + ':topics', tid);
|
||||||
|
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
title: 'Thank you for posting',
|
||||||
|
message: 'You have successfully posted. Click here to view your post.',
|
||||||
|
type: 'notify',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
|
||||||
|
// let everyone know that there is an unread topic in this category
|
||||||
|
RDB.del('cid:' + category_id + ':read_by_uid');
|
||||||
|
|
||||||
|
RDB.zadd('topics:recent', (new Date()).getTime(), tid);
|
||||||
|
//RDB.zadd('topics:active', tid);
|
||||||
|
|
||||||
|
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
||||||
|
RDB.sadd('categories:' + category_id + ':tid', tid);
|
||||||
|
RDB.set('tid:' + tid + ':cid', category_id);
|
||||||
|
categories.getCategories([category_id], function(data) {
|
||||||
|
RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
|
||||||
|
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
|
||||||
|
});
|
||||||
|
|
||||||
|
RDB.incr('cid:' + category_id + ':topiccount');
|
||||||
});
|
});
|
||||||
|
|
||||||
Topics.markAsRead(tid, uid);
|
|
||||||
|
|
||||||
// User Details - move this out later
|
|
||||||
RDB.lpush('uid:' + uid + ':topics', tid);
|
|
||||||
|
|
||||||
socket.emit('event:alert', {
|
|
||||||
title: 'Thank you for posting',
|
|
||||||
message: 'You have successfully posted. Click here to view your post.',
|
|
||||||
type: 'notify',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
|
|
||||||
// let everyone know that there is an unread topic in this category
|
|
||||||
RDB.del('cid:' + category_id + ':read_by_uid');
|
|
||||||
|
|
||||||
RDB.zadd('topics:recent', (new Date()).getTime(), tid);
|
|
||||||
//RDB.zadd('topics:active', tid);
|
|
||||||
|
|
||||||
// in future it may be possible to add topics to several categories, so leaving the door open here.
|
|
||||||
RDB.sadd('categories:' + category_id + ':tid', tid);
|
|
||||||
RDB.set('tid:' + tid + ':cid', category_id);
|
|
||||||
categories.getCategories([category_id], function(data) {
|
|
||||||
RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
|
|
||||||
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
|
|
||||||
});
|
|
||||||
|
|
||||||
RDB.incr('cid:' + category_id + ':topiccount');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,8 @@ var config = require('../config.js'),
|
|||||||
'gravatarpicture' : gravatar,
|
'gravatarpicture' : gravatar,
|
||||||
'uploadedpicture': '',
|
'uploadedpicture': '',
|
||||||
'reputation': 0,
|
'reputation': 0,
|
||||||
'postcount': 0
|
'postcount': 0,
|
||||||
|
'lastposttime': 0
|
||||||
});
|
});
|
||||||
|
|
||||||
RDB.set('username:' + username + ':uid', uid);
|
RDB.set('username:' + username + ':uid', uid);
|
||||||
|
|||||||
Reference in New Issue
Block a user