Conflicts:
	src/posts.js
v1.18.x
psychobunny 12 years ago
commit 6db259cf3f

@ -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 : '') + '/';

@ -38,27 +38,21 @@ var socket,
socket.on('connect', function(data){ socket.on('connect', function(data){
if(reconnecting) { if(reconnecting) {
app.alert({ setTimeout(function(){
alert_id: 'connection_alert', app.alert({
title: 'Connected', alert_id: 'connection_alert',
message: 'Connection successful', title: 'Connected',
type: 'success', message: 'Connection successful.',
timeout: 5000 type: 'success',
}); timeout: 5000
});
}, 1000);
reconnecting = false; reconnecting = false;
} }
}); });
socket.on('disconnect', function(data){ socket.on('disconnect', function(data){
setTimeout(function() {
app.alert({
alert_id: 'connection_alert',
title: 'Disconnect',
message: 'You have disconnected from NodeBB, we will try to reconnect!',
type: 'error',
timeout: 5000
});
}, 500);
}); });
socket.on('reconnecting', function(data) { socket.on('reconnecting', function(data) {

@ -125,8 +125,10 @@
}); });
socket.on('api:notifications.counts', function(counts) { socket.on('api:notifications.counts', function(counts) {
var notifIcon = document.querySelector('.notifications a i'); var notifIcon = document.querySelector('.notifications a i');
if (counts.unread > 0) notifIcon.className = 'icon-circle active'; if(notifIcon) {
else notifIcon.className = 'icon-circle-blank'; if (counts.unread > 0) notifIcon.className = 'icon-circle active';
else notifIcon.className = 'icon-circle-blank';
}
}); });
socket.on('event:new_notification', function() { socket.on('event:new_notification', function() {
console.log('WOOT'); console.log('WOOT');

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

@ -290,68 +290,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);
if(new Date().getTime() - lastposttime < config.post_delay) {
// Global Topics socket.emit('event:alert', {
if (uid == null) uid = 0; title: 'Too many posts!',
if (uid !== null) { message: 'You can only post every '+ (config.post_delay / 1000) + ' seconds.',
RDB.sadd('topics:tid', tid); type: 'error',
} else { timeout: 2000
// 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); return;
} }
var slug = tid + '/' + utils.slugify(title); RDB.incr('global:next_topic_id', function(err, tid) {
RDB.handle(err);
// Global Topics
if (uid == null) uid = 0;
if (uid !== null) {
RDB.sadd('topics:tid', tid);
} 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);
}
// Topic Info var slug = tid + '/' + utils.slugify(title);
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());
// 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 RDB.set('topic:slug:' + slug + ':tid', tid);
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 // Posts
Topics.get_topic(tid, uid, function(topicData) { posts.create(uid, tid, content, function(pid) {
io.sockets.in('category_' + category_id).emit('event:new_topic', topicData); 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); Topics.markAsRead(tid, uid);
// User Details - move this out later // User Details - move this out later
RDB.lpush('uid:' + uid + ':topics', tid); RDB.lpush('uid:' + uid + ':topics', tid);
socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Thank you for posting', title: 'Thank you for posting',
message: 'You have successfully posted. Click here to view your post.', message: 'You have successfully posted. Click here to view your post.',
type: 'notify', type: 'notify',
timeout: 2000 timeout: 2000
}); });
// let everyone know that there is an unread topic in this category // let everyone know that there is an unread topic in this category
RDB.del('cid:' + category_id + ':read_by_uid'); RDB.del('cid:' + category_id + ':read_by_uid');
RDB.zadd('topics:recent', (new Date()).getTime(), tid); RDB.zadd('topics:recent', (new Date()).getTime(), tid);
//RDB.zadd('topics:active', tid); //RDB.zadd('topics:active', tid);
// in future it may be possible to add topics to several categories, so leaving the door open here. // 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.sadd('categories:' + category_id + ':tid', tid);
RDB.set('tid:' + tid + ':cid', category_id); RDB.set('tid:' + tid + ':cid', category_id);
categories.getCategories([category_id], function(data) { categories.getCategories([category_id], function(data) {
RDB.set('tid:' + tid + ':category_name', data.categories[0].name); RDB.set('tid:' + tid + ':category_name', data.categories[0].name);
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug); RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
}); });
RDB.incr('cid:' + category_id + ':topiccount'); RDB.incr('cid:' + category_id + ':topiccount');
});
}); });
}; };

@ -196,8 +196,8 @@ var config = require('../config.js'),
callback(err); callback(err);
} else { } else {
// Save twitter-specific information to the user // Save twitter-specific information to the user
RDB.set('uid:' + uid + ':twid', twid); User.setUserField(uid, 'twid', twid);
RDB.set('twid:' + twid + ':uid', uid); RDB.hset('twid:uid', twid, uid);
callback(null, { callback(null, {
uid: uid uid: uid
}); });
@ -216,17 +216,23 @@ var config = require('../config.js'),
}); });
} else { } else {
// New User // New User
User.create(handle, null, email, function(err, uid) { var success = function(uid) {
if (err !== null) { // Save google-specific information to the user
callback(err); User.setUserField(uid, 'gplusid', gplusid);
} else { RDB.hset('gplusid:uid', gplusid, uid);
// Save twitter-specific information to the user callback(null, {
RDB.set('uid:' + uid + ':gplusid', gplusid); uid: uid
RDB.set('gplusid:' + gplusid + ':uid', uid); });
callback(null, { }
uid: uid
User.get_uid_by_email(email, function(uid) {
if (!uid) {
User.create(handle, null, email, function(err, uid) {
if (err !== null) {
callback(err);
} else success(uid);
}); });
} } else success(uid); // Existing account -- merge
}); });
} }
}); });
@ -241,17 +247,23 @@ var config = require('../config.js'),
}); });
} else { } else {
// New User // New User
User.create(name, null, email, function(err, uid) { var success = function(uid) {
if (err !== null) { // Save facebook-specific information to the user
callback(err); User.setUserField(uid, 'fbid', fbid);
} else { RDB.hset('fbid:uid', fbid, uid);
// Save twitter-specific information to the user
RDB.set('uid:' + uid + ':fbid', fbid);
RDB.set('fbid:' + fbid + ':uid', uid);
callback(null, { callback(null, {
uid: uid uid: uid
}); });
} }
User.get_uid_by_email(email, function(uid) {
if (!uid) {
User.create(name, null, email, function(err, uid) {
if (err !== null) {
callback(err);
} else success(uid);
});
} else success(uid); // Existing account -- merge
}); });
} }
}); });
@ -288,7 +300,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);
@ -493,21 +506,21 @@ var config = require('../config.js'),
}; };
User.get_uid_by_twitter_id = function(twid, callback) { User.get_uid_by_twitter_id = function(twid, callback) {
RDB.get('twid:' + twid + ':uid', function(err, uid) { RDB.hget('twid:uid', twid, function(err, uid) {
RDB.handle(err); RDB.handle(err);
callback(uid); callback(uid);
}); });
} }
User.get_uid_by_google_id = function(gplusid, callback) { User.get_uid_by_google_id = function(gplusid, callback) {
RDB.get('gplusid:' + gplusid + ':uid', function(err, uid) { RDB.hget('gplusid:uid', gplusid, function(err, uid) {
RDB.handle(err); RDB.handle(err);
callback(uid); callback(uid);
}); });
} }
User.get_uid_by_fbid = function(fbid, callback) { User.get_uid_by_fbid = function(fbid, callback) {
RDB.get('fbid:' + fbid + ':uid', function(err, uid) { RDB.hget('fbid:uid', fbid, function(err, uid) {
RDB.handle(err); RDB.handle(err);
callback(uid); callback(uid);
}); });

Loading…
Cancel
Save