Skip to content

Node.js based forum software built for the modern web

fixed a bug that made topics invisible to users, also closes #47

Baris Soner Usaklied99f2671e8e
diff --git a/public/src/utils.js b/public/src/utils.js
index 1cde4e1360..0a62e22e0e 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -86,7 +86,7 @@
// from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
isEmailValid: function(email) {
var re = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
- return re.test(email);
+ return re.test(email);
},
isUserNameValid: function(name) {
diff --git a/src/categories.js b/src/categories.js
index 036fb5b490..c9c9bf02b6 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -12,7 +12,7 @@ var RDB = require('./redis.js'),
Categories.getCategoryData(category_id, function(categoryData) {
- var category_name = categoryData.name;
+ var category_name = categoryData.name;
category_slug = categoryData.slug;
RDB.smembers('cid:' + category_id + ':active_users', function(err, active_users) {
@@ -160,8 +160,11 @@ var RDB = require('./redis.js'),
});
});
}
-
+ function isTopicVisible(topicData, topicInfo) {
+ var deleted = parseInt(topicData.deleted, 10) !== 0;
+ return !deleted || (deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user;
+ }
for(var i=0; i<tids.length; ++i) {
@@ -180,8 +183,8 @@ var RDB = require('./redis.js'),
topicData.teaser_text = topicInfo.teaserInfo.text,
topicData.teaser_username = topicInfo.teaserInfo.username;
topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp);
-
- if (!topicData.deleted || (topicData.deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user)
+
+ if (isTopicVisible(topicData, topicInfo))
retrieved_topics.push(topicData);
else
--topicCountToLoad;
@@ -301,6 +304,14 @@ var RDB = require('./redis.js'),
console.log(err);
});
}
+
+ Categories.setCategoryField = function(cid, field, value) {
+ RDB.hset('category:' + cid, field, value);
+ }
+
+ Categories.incrementCategoryFieldBy = function(cid, field, value) {
+ RDB.hincrby('category:' + cid, field, value);
+ }
Categories.getCategories = function(cids, callback, current_user) {
if (cids.length === 0) {
diff --git a/src/threadTools.js b/src/threadTools.js
index d0a0cbfd6c..b192b179d5 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -167,6 +167,9 @@ var RDB = require('./redis.js'),
if (!err && result === 1) {
topics.setTopicField(tid, 'cid', cid);
+
+ categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
+ categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
categories.getCategories([cid], function(data) {
topics.setTopicField(tid, 'category_name', data.categories[0].name);
diff --git a/src/webserver.js b/src/webserver.js
index a26071b5bd..860130baca 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -162,6 +162,7 @@ var express = require('express'),
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
categories.getCategoryById(cid, 0, function(returnData) {
+
res.send(
app.build_header(res) +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +