From 24e79b3f4e597d49076aef7e34013f99f59e05ea Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 21 Oct 2013 18:51:33 -0400 Subject: [PATCH 1/9] #426 --- public/src/forum/footer.js | 5 +++-- public/templates/header.tpl | 40 +++++++++++++++++++++---------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index 31e96395df..15061a6424 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -58,9 +58,10 @@ $('#search-button').show(); var userLabel = loggedInMenu.find('#user_label'); + if (userLabel.length) { if (data['userslug']) - userLabel.attr('href', '/user/' + data['userslug']); + userLabel.find('#user-profile-link').attr('href', '/user/' + data['userslug']); if (data['picture']) userLabel.find('img').attr('src', data['picture']); if (data['username']) @@ -87,7 +88,7 @@ } - $('#main-nav a,#right-menu a').off('click').on('click', function() { + $('#main-nav a,#user-control-list a').off('click').on('click', function() { if($('.navbar .navbar-collapse').hasClass('in')) $('.navbar-header button').click(); }); diff --git a/public/templates/header.tpl b/public/templates/header.tpl index e0056401b0..4b25b60dcd 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -72,6 +72,18 @@ +
  • + +
  • + -
  • - +
  • - - - - + - + - + From 9babef0095527c35c2255bc3a28788f6184632b9 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Tue, 22 Oct 2013 13:42:23 -0400 Subject: [PATCH 7/9] closes #422, will restart over if reconnection fails after x number of attempts --- public/src/app.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 3feb9b3f2e..daf8fb2427 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -21,7 +21,12 @@ var socket, socket.socket.connect(); }, 200); } else { - socket = io.connect(RELATIVE_PATH); + var max_reconnection_attemps = 5; + var reconnection_delay = 200; + socket = io.connect(RELATIVE_PATH, { + 'max reconnection attempts': max_reconnection_attemps, + 'reconnection delay': reconnection_delay + }); var reconnecting = false, reconnectEl, reconnectTimer; @@ -59,7 +64,13 @@ var socket, socket.socket.connect(); }); - socket.on('reconnecting', function (data) { + socket.on('reconnecting', function (data, attempt) { + if(attempt == max_reconnection_attemps) { + socket.socket.reconnectionAttempts = 0; + socket.socket.reconnectionDelay = reconnection_delay; + return; + } + if (!reconnectEl) reconnectEl = $('#reconnect'); reconnecting = true; @@ -322,7 +333,7 @@ var socket, if (data.posts[0].uid !== app.uid) { data.posts[0].display_moderator_tools = 'none'; } - + var html = templates.prepare(templates['topic'].blocks['posts']).parse(data); translator.translate(html, function(translatedHTML) { var uniqueid = new Date().getTime(), From 51395dda91b72deafce61c3a88a194ac680c2dc1 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 22 Oct 2013 14:22:16 -0400 Subject: [PATCH 8/9] updated all RDB.hget in posts to use getPostField. new post filters for retrieving and saving posts. made editPost saving synchronous. --- src/postTools.js | 17 +++++++++++--- src/posts.js | 57 ++++++++++++++++++++++++++++++++++++---------- src/threadTools.js | 2 +- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index ca3dd2dae0..bdf69943d6 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -61,9 +61,20 @@ var RDB = require('./redis.js'), PostTools.edit = function(uid, pid, title, content) { var success = function() { - posts.setPostField(pid, 'content', content); - posts.setPostField(pid, 'edited', Date.now()); - posts.setPostField(pid, 'editor', uid); + async.waterfall([ + function(next) { + posts.setPostField(pid, 'edited', Date.now()); + next(null); + }, + function(next) { + posts.setPostField(pid, 'editor', uid); + next(null); + }, + function(next) { + posts.setPostField(pid, 'content', content); + next(null); + } + ]); postSearch.remove(pid, function() { postSearch.index(content, pid); diff --git a/src/posts.js b/src/posts.js index ef285a8bcd..248e042d1e 100644 --- a/src/posts.js +++ b/src/posts.js @@ -24,9 +24,16 @@ var RDB = require('./redis.js'), RDB.handle(err); if (pids.length) { - Posts.getPostsByPids(pids, function(err, posts) { - callback(posts); - }); + plugins.fireHook('filter:post.getTopic', pids, function(err, posts) { + if (!err & 0 < posts.length) { + Posts.getPostsByPids(pids, function(err, posts) { + plugins.fireHook('action:post.gotTopic', posts); + callback(posts); + }); + } else { + callback(posts); + } + }); } else { callback([]); } @@ -131,6 +138,7 @@ var RDB = require('./redis.js'), }); } + // TODO: this function is never called except from some debug route. clean up? Posts.getPostData = function(pid, callback) { RDB.hgetall('post:' + pid, function(err, data) { if (err === null) { @@ -146,7 +154,14 @@ var RDB = require('./redis.js'), Posts.getPostFields = function(pid, fields, callback) { RDB.hmgetObject('post:' + pid, fields, function(err, data) { if (err === null) { - callback(data); + // TODO: I think the plugins system needs an optional 'parameters' paramter so I don't have to do this: + data = data || {}; + data.pid = pid; + data.fields = fields; + + plugins.fireHook('filter:post.getFields', data, function(err, data) { + callback(data); + }); } else { console.log(err); } @@ -155,15 +170,28 @@ var RDB = require('./redis.js'), Posts.getPostField = function(pid, field, callback) { RDB.hget('post:' + pid, field, function(err, data) { - if (err === null) - callback(data); - else + if (err === null) { + // TODO: I think the plugins system needs an optional 'parameters' paramter so I don't have to do this: + data = data || {}; + data.pid = pid; + data.field = field; + + plugins.fireHook('filter:post.getField', data, function(err, data) { + callback(data); + }); + } else { console.log(err); + } }); } - Posts.setPostField = function(pid, field, value) { + Posts.setPostField = function(pid, field, value, done) { RDB.hset('post:' + pid, field, value); + plugins.fireHook('action:post.setField', { + 'pid': pid, + 'field': field, + 'value': value + }, done); } Posts.getPostsByPids = function(pids, callback) { @@ -402,11 +430,16 @@ var RDB = require('./redis.js'), Posts.getPostsByUid = function(uid, start, end, callback) { user.getPostIds(uid, start, end, function(pids) { - if (pids && pids.length) { - - Posts.getPostsByPids(pids, function(err, posts) { - callback(posts); + plugins.fireHook('filter:post.getTopic', pids, function(err, posts) { + if (!err & 0 < posts.length) { + Posts.getPostsByPids(pids, function(err, posts) { + plugins.fireHook('action:post.gotTopic', posts); + callback(posts); + }); + } else { + callback(posts); + } }); } else callback([]); diff --git a/src/threadTools.js b/src/threadTools.js index 478f25fd7e..e375876ef0 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -303,7 +303,7 @@ var RDB = require('./redis.js'), pids.reverse(); async.detectSeries(pids, function(pid, next) { - RDB.hget('post:' + pid, 'deleted', function(err, deleted) { + posts.getPostField(pid, 'deleted', function(deleted) { if (deleted === '0') next(true); else next(false); }); From 2ee29683a7de070f24c813ea2e986e46ead54d1d Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 22 Oct 2013 14:22:53 -0400 Subject: [PATCH 9/9] random whitespace --- src/posts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/posts.js b/src/posts.js index 248e042d1e..5199be6f2d 100644 --- a/src/posts.js +++ b/src/posts.js @@ -428,7 +428,6 @@ var RDB = require('./redis.js'), } Posts.getPostsByUid = function(uid, start, end, callback) { - user.getPostIds(uid, start, end, function(pids) { if (pids && pids.length) { plugins.fireHook('filter:post.getTopic', pids, function(err, posts) {