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

v1.18.x
Baris Soner Usakli 12 years ago
parent 8dd7c5fdd1
commit ed99f2671e

@ -86,7 +86,7 @@
// from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript // from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
isEmailValid: function(email) { 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])?/; 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) { isUserNameValid: function(name) {

@ -12,7 +12,7 @@ var RDB = require('./redis.js'),
Categories.getCategoryData(category_id, function(categoryData) { Categories.getCategoryData(category_id, function(categoryData) {
var category_name = categoryData.name; var category_name = categoryData.name;
category_slug = categoryData.slug; category_slug = categoryData.slug;
RDB.smembers('cid:' + category_id + ':active_users', function(err, active_users) { 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) { 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_text = topicInfo.teaserInfo.text,
topicData.teaser_username = topicInfo.teaserInfo.username; topicData.teaser_username = topicInfo.teaserInfo.username;
topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp); 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); retrieved_topics.push(topicData);
else else
--topicCountToLoad; --topicCountToLoad;
@ -301,6 +304,14 @@ var RDB = require('./redis.js'),
console.log(err); 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) { Categories.getCategories = function(cids, callback, current_user) {
if (cids.length === 0) { if (cids.length === 0) {

@ -167,6 +167,9 @@ var RDB = require('./redis.js'),
if (!err && result === 1) { if (!err && result === 1) {
topics.setTopicField(tid, 'cid', cid); topics.setTopicField(tid, 'cid', cid);
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
categories.getCategories([cid], function(data) { categories.getCategories([cid], function(data) {
topics.setTopicField(tid, 'category_name', data.categories[0].name); topics.setTopicField(tid, 'category_name', data.categories[0].name);

@ -162,6 +162,7 @@ var express = require('express'),
var category_url = cid + (req.params.slug ? '/' + req.params.slug : ''); var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
categories.getCategoryById(cid, 0, function(returnData) { categories.getCategoryById(cid, 0, function(returnData) {
res.send( res.send(
app.build_header(res) + app.build_header(res) +
'\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' + '\n\t<noscript>\n' + templates['noscript/header'] + templates['noscript/category'].parse(returnData) + '\n\t</noscript>' +

Loading…
Cancel
Save