post every x seconds added it x to config

v1.18.x
Baris Usakli 12 years ago
parent eeb70b17ba
commit db6bbcc699

@ -59,7 +59,8 @@ var config = {
},
"show_motd": true,
"motd": undefined
"motd": undefined,
"post_delay" : 10000
}
config.url = config.base_url + (config.use_port ? ':' + config.port : '') + '/';

@ -127,6 +127,18 @@ marked.setOptions({
return;
}
user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(new Date().getTime() - lastposttime < config.post_delay) {
socket.emit('event:alert', {
title: 'Too many posts!',
message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.',
type: 'error',
timeout: 2000
});
return;
}
Posts.create(uid, tid, content, function(pid) {
if (pid > 0) {
RDB.rpush('tid:' + tid + ':posts', pid);
@ -182,6 +194,7 @@ marked.setOptions({
});
}
});
});
};
Posts.create = function(uid, tid, content, callback) {
@ -194,10 +207,11 @@ marked.setOptions({
RDB.incr('global:next_post_id', function(err, pid) {
RDB.handle(err);
var timestamp = new Date().getTime();
// Posts Info
RDB.set('pid:' + pid + ':content', content);
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 + ':tid', tid);
@ -225,6 +239,7 @@ marked.setOptions({
RDB.lpush('uid:' + uid + ':posts', pid);
user.incrementUserFieldBy(uid, 'postcount', 1);
user.setUserField(uid, 'lastposttime', timestamp);
if (callback)
callback(pid);

@ -295,6 +295,18 @@ marked.setOptions({
return; // for now, until anon code is written.
}
user.getUserField(uid, 'lastposttime', function(lastposttime) {
if(new Date().getTime() - lastposttime < config.post_delay) {
socket.emit('event:alert', {
title: 'Too many posts!',
message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.',
type: 'error',
timeout: 2000
});
return;
}
RDB.incr('global:next_topic_id', function(err, tid) {
RDB.handle(err);
@ -358,6 +370,7 @@ marked.setOptions({
RDB.incr('cid:' + category_id + ':topiccount');
});
});
};
}(exports));

@ -288,7 +288,8 @@ var config = require('../config.js'),
'gravatarpicture' : gravatar,
'uploadedpicture': '',
'reputation': 0,
'postcount': 0
'postcount': 0,
'lastposttime': 0
});
RDB.set('username:' + username + ':uid', uid);

Loading…
Cancel
Save