From a87ebb64d86ac91f629c92379bfc6b67ea2ab4e3 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 28 Nov 2013 15:18:19 -0500 Subject: [PATCH 1/7] clean up of posts and some template additions --- public/src/app.js | 6 +++--- public/src/forum/topic.js | 4 ---- public/templates/account.tpl | 4 +++- public/templates/topic.tpl | 26 ++++++++++++++++++++------ src/feed.js | 12 +++++++++--- src/posts.js | 32 ++++++++++++++++++-------------- src/routes/user.js | 12 ++++++------ src/topics.js | 5 ++--- 8 files changed, 61 insertions(+), 40 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index c29f24fa03..4be2beb8b9 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -297,8 +297,8 @@ var socket, }); } - app.makeNumbersHumanReadable = function() { - $('.human-readable-number').each(function() { + app.makeNumbersHumanReadable = function(selector) { + $(selector).each(function() { var num = parseInt($(this).html(), 10); $(this).html(utils.makeNumberHumanReadable(num)); }); @@ -312,7 +312,7 @@ var socket, $('span.timeago').timeago(); $('.post-content img').addClass('img-responsive'); - app.makeNumbersHumanReadable(); + app.makeNumbersHumanReadable('.human-readable-number'); app.createUserTooltips(); diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index e0628551e8..f44a327760 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -866,10 +866,6 @@ define(function() { if(!data || (data.posts && !data.posts.length)) return; - if (data.posts[0].uid !== app.uid) { - data.posts[0].display_moderator_tools = 'none'; - } - function removeAlreadyAddedPosts() { data.posts = data.posts.filter(function(post) { return $('#post-container li[data-pid="' + post.pid +'"]').length === 0; diff --git a/public/templates/account.tpl b/public/templates/account.tpl index 6d5335ac42..7327cca25f 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -15,9 +15,11 @@
offline
-
+ +
banned
+
Follow Unfollow diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl index b7755ccee2..d4e0c41bb8 100644 --- a/public/templates/topic.tpl +++ b/public/templates/topic.tpl @@ -36,7 +36,9 @@ @@ -64,9 +66,17 @@
-
@@ -82,10 +92,12 @@
+
- - + +
+
@@ -102,8 +114,10 @@ posted - | last edited by {posts.editorname} + + | last edited by {posts.editorname} +
diff --git a/src/feed.js b/src/feed.js index 7608648850..8251d70cff 100644 --- a/src/feed.js +++ b/src/feed.js @@ -29,7 +29,9 @@ Feed.updateTopic = function (tid, callback) { topics.getTopicWithPosts(tid, 0, 0, -1, function (err, topicData) { - if (err) return callback(new Error('topic-invalid')); + if (err) { + return callback(new Error('topic-invalid')); + } var feed = new rss({ title: topicData.topic_name, @@ -44,7 +46,9 @@ dateStamp; // Add pubDate if topic contains posts - if (topicData.posts.length > 0) feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString(); + if (topicData.posts.length > 0) { + feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString(); + } async.each(topic_posts, function(postData, next) { if (postData.deleted === '0') { @@ -65,7 +69,9 @@ winston.info('[rss] Re-generated RSS Feed for tid ' + tid + '.'); } - if (callback) callback(); + if (callback) { + callback(); + } }); }); diff --git a/src/posts.js b/src/posts.js index 4a885a0876..bc1336ce81 100644 --- a/src/posts.js +++ b/src/posts.js @@ -54,18 +54,25 @@ var RDB = require('./redis'), 'reputation': 0, 'editor': '', 'edited': 0, - 'deleted': 0, - 'fav_button_class': '', - 'fav_star_class': 'fa-star-o', - 'show_banned': 'hide', - 'relativeTime': new Date(timestamp).toISOString(), - 'post_rep': '0', - 'edited-class': 'none', - 'relativeEditTime': '' + 'deleted': 0 + //TODO : write upgrade script to remove these fields from the database -barisu + //'fav_button_class': '', + //'fav_star_class': 'fa-star-o', + //'show_banned': 'hide', + //'relativeTime': new Date(timestamp).toISOString(), + //'post_rep': '0', + //'edited-class': 'none', + //'relativeEditTime': '' }; RDB.hmset('post:' + pid, postData); + postData.favourited = false; + postData.display_moderator_tools = true; + postData.relativeTime = new Date(timestamp).toISOString(); + //TODO : remove this once template bug is fixed -barisu (https://github.com/designcreateplay/NodeBB/issues/574) + postData.fav_star_class = 'fa-star-o'; + topics.addPostToTopic(tid, pid); topics.increasePostCount(tid); topics.updateTimestamp(tid, timestamp); @@ -78,8 +85,8 @@ var RDB = require('./redis'), var cid = topicData.cid; - feed.updateTopic(tid); - feed.updateRecent(); + //feed.updateTopic(tid); + //feed.updateRecent(); RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid); @@ -178,7 +185,6 @@ var RDB = require('./redis'), if(err) { return callback(err, null); } - callback(null, postData); }); }); @@ -217,7 +223,7 @@ var RDB = require('./redis'), post.userslug = userData.userslug || ''; post.user_rep = userData.reputation || 0; post.user_postcount = userData.postcount || 0; - post.user_banned = userData.banned || '0'; + post.user_banned = userData.banned === '1'; post.picture = userData.picture || require('gravatar').url('', {}, https = nconf.get('https')); post.signature = signature; @@ -367,8 +373,6 @@ var RDB = require('./redis'), async.map(replies, function(postData, _callback) { if (postData) { - postData.post_rep = postData.reputation; - postData['edited-class'] = postData.editor !== '' ? '' : 'none'; try { postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString(); postData.relativeEditTime = postData.edited !== '0' ? (new Date(parseInt(postData.edited,10)).toISOString()) : ''; diff --git a/src/routes/user.js b/src/routes/user.js index 5bdee2c5d0..12610cbc59 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -535,18 +535,18 @@ var user = require('./../user.js'), return callerUID == uid || (data.email && (data.showemail && data.showemail === "1")); } - if (!canSeeEmail()) + if (!canSeeEmail()) { data.email = ""; + } - if (callerUID == uid && (!data.showemail || data.showemail === "0")) + if (callerUID == uid && (!data.showemail || data.showemail === "0")) { data.emailClass = ""; - else + } else { data.emailClass = "hide"; + } data.websiteName = data.website.replace('http://', '').replace('https://', ''); - - data.show_banned = data.banned === '1' ? '' : 'hide'; - + data.banned = data.banned === '1'; data.uid = uid; data.yourid = callerUID; data.theirid = uid; diff --git a/src/topics.js b/src/topics.js index b556e7cc88..4a9c7e977c 100644 --- a/src/topics.js +++ b/src/topics.js @@ -196,11 +196,10 @@ var RDB = require('./redis'), privileges = results[2]; for (var i = 0; i < postData.length; ++i) { + postData[i].favourited = fav_data[postData[i].pid] === 1; postData[i].fav_button_class = fav_data[postData[i].pid] ? 'btn-warning' : ''; postData[i].fav_star_class = fav_data[postData[i].pid] ? 'fa-star' : 'fa-star-o'; - postData[i]['display_moderator_tools'] = ((current_user != 0) && (postData[i].uid == current_user || privileges.editable)) ? 'show' : 'none'; - - postData[i].show_banned = postData[i].user_banned === '1' ? 'show' : 'hide'; + postData[i].display_moderator_tools = ((current_user != 0) && (postData[i].uid == current_user || privileges.editable)); } callback(postData); From 168052bf45ed8b828386b498ce03ef868b27f4e8 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 28 Nov 2013 15:33:26 -0500 Subject: [PATCH 2/7] added back feeds, removed duplicate post var in feed --- src/feed.js | 3 +-- src/posts.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/feed.js b/src/feed.js index 8251d70cff..522edab086 100644 --- a/src/feed.js +++ b/src/feed.js @@ -42,7 +42,6 @@ author: topicData.posts[0].username, ttl: Feed.defaults.ttl }), - topic_posts = topicData.posts.concat(topicData.posts), dateStamp; // Add pubDate if topic contains posts @@ -50,7 +49,7 @@ feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString(); } - async.each(topic_posts, function(postData, next) { + async.each(topicData.posts, function(postData, next) { if (postData.deleted === '0') { dateStamp = new Date(parseInt(postData.edited === '0' ? postData.timestamp : postData.edited, 10)).toUTCString(); diff --git a/src/posts.js b/src/posts.js index bc1336ce81..b3be7dfe66 100644 --- a/src/posts.js +++ b/src/posts.js @@ -85,8 +85,8 @@ var RDB = require('./redis'), var cid = topicData.cid; - //feed.updateTopic(tid); - //feed.updateRecent(); + feed.updateTopic(tid); + feed.updateRecent(); RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid); From ae82f57c67a0a85bfed0de3a7acb4285247b37dd Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 28 Nov 2013 15:55:40 -0500 Subject: [PATCH 3/7] added upgrade script to delete removed keys from posts --- src/upgrade.js | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/upgrade.js b/src/upgrade.js index cec799914d..0780f1a0f7 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -11,7 +11,7 @@ var RDB = require('./redis.js'), Upgrade.check = function(callback) { // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema - var latestSchema = new Date(2013, 10, 26).getTime(); + var latestSchema = new Date(2013, 10, 28).getTime(); RDB.get('schemaDate', function(err, value) { if (parseInt(value, 10) >= latestSchema) { @@ -179,7 +179,7 @@ Upgrade.upgrade = function(callback) { }, function(next) { thisSchemaDate = new Date(2013, 10, 26).getTime(); - if (schemaDate < thisSchemaDate || 1) { + if (schemaDate < thisSchemaDate) { categories.getAllCategories(0, function(err, categories) { function updateIcon(category, next) { @@ -209,6 +209,41 @@ Upgrade.upgrade = function(callback) { winston.info('[2013/11/26] Update to Category icons skipped.'); next(); } + }, + function(next) { + thisSchemaDate = new Date(2013, 10, 28).getTime(); + if (schemaDate < thisSchemaDate) { + var keysToDelete = [ + 'fav_button_class', + 'fav_star_class', + 'show_banned', + 'relativeTime', + 'post_rep', + 'edited-class', + 'relativeEditTime' + ]; + + RDB.keys('post:*', function(err, posts) { + if(err) { + return next(err); + } + + function deleteRemovedData(key, callback) { + RDB.hdel(key, keysToDelete, callback) + } + + async.each(posts, deleteRemovedData, function(err) { + if(err) { + return next(err); + } + winston.info('[2013/11/28] Deleted removed post data.'); + next(err); + }); + }); + } else { + winston.info('[2013/11/26] Update to Post data skipped.'); + next(); + } } // Add new schema updates here // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 12!!! From 4335f8c5c6c99eb773dd856f11c171391390aa0f Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 28 Nov 2013 15:57:00 -0500 Subject: [PATCH 4/7] fixed date in upgrade --- src/upgrade.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/upgrade.js b/src/upgrade.js index 0780f1a0f7..b74dac23b5 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -241,7 +241,7 @@ Upgrade.upgrade = function(callback) { }); }); } else { - winston.info('[2013/11/26] Update to Post data skipped.'); + winston.info('[2013/11/28] Update to Post data skipped.'); next(); } } From f2bf65252d411a779d05958ca99c85c856f2f7f3 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 28 Nov 2013 16:15:18 -0500 Subject: [PATCH 5/7] removed the fields --- public/src/templates.js | 18 +++++++++--------- public/templates/topic.tpl | 2 +- src/posts.js | 8 -------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/public/src/templates.js b/public/src/templates.js index d933a7db74..7815568d5a 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -312,20 +312,20 @@ function checkConditional(key, value) { var conditional = makeConditionalRegex(key), conditionalBlock = conditional.exec(template); - + if (conditionalBlock !== null) { conditionalBlock = conditionalBlock[0].split(//); - + if (conditionalBlock[1]) { // there is an else statement if (!value) { - template = template.replace(conditional, conditionalBlock[1]); + template = template.replace(conditional, conditionalBlock[1]); } else { - template = template.replace(conditional, conditionalBlock[0]); + template = template.replace(conditional, conditionalBlock[0]); } - + } else { - // regular if + // regular if if (!value) { template = template.replace(conditional, ''); } @@ -335,13 +335,13 @@ checkConditional(namespace + d, data[d]); checkConditional('!' + namespace + d, !data[d]); - + if (blockInfo) { checkConditional('@first', blockInfo.iterator === 0); checkConditional('@last', blockInfo.iterator === blockInfo.total); } - - + + template = replace(namespace + d, data[d], template); } } diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl index d4e0c41bb8..ae9b3110b3 100644 --- a/public/templates/topic.tpl +++ b/public/templates/topic.tpl @@ -66,7 +66,7 @@
- - -