Skip to content

Node.js based forum software built for the modern web

some cleanup of unread

Baris Soner Usaklieb3b240b0475
diff --git a/src/categories.js b/src/categories.js
index 0e47e7b1a8..2049b22c99 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -171,8 +171,14 @@ var db = require('./database'),
Categories.isTopicsRead = function(cid, uid, callback) {
db.getSortedSetRange('categories:' + cid + ':tid', 0, -1, function(err, tids) {
+ if(err) {
+ return callback(err);
+ }
- topics.hasReadTopics(tids, uid, function(hasRead) {
+ topics.hasReadTopics(tids, uid, function(err, hasRead) {
+ if(err) {
+ return callback(err);
+ }
var allread = true;
for (var i = 0, ii = tids.length; i < ii; i++) {
@@ -271,8 +277,6 @@ var db = require('./database'),
});
};
-
-
Categories.getCategoryData = function(cid, callback) {
db.exists('category:' + cid, function(err, exists) {
if (exists) {
diff --git a/src/database/mongo.js b/src/database/mongo.js
index 6bd0b5037e..63338856f6 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -20,7 +20,6 @@
module.init = function(callback) {
-
mongoClient.connect('mongodb://'+ nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'), function(err, _db) {
if(err) {
winston.error("NodeBB could not connect to your Mongo database. Mongo returned the following error: " + err.message);
diff --git a/src/topics.js b/src/topics.js
index bdcd055526..6ad23bee70 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -518,8 +518,10 @@ var async = require('async'),
return callback(null);
}
- Topics.hasReadTopics(tids, uid, function(read) {
-
+ Topics.hasReadTopics(tids, uid, function(err, read) {
+ if(err) {
+ return callback(err);
+ }
var newtids = tids.filter(function(tid, index, self) {
return read[index] === 0;
});
@@ -563,8 +565,10 @@ var async = require('async'),
unreadTids.push.apply(unreadTids, tids);
callback(null);
} else {
- Topics.hasReadTopics(tids, uid, function(read) {
-
+ Topics.hasReadTopics(tids, uid, function(err, read) {
+ if(err) {
+ return callback(err);
+ }
var newtids = tids.filter(function(tid, index, self) {
return parseInt(read[index], 10) === 0;
});
@@ -572,11 +576,7 @@ var async = require('async'),
async.filter(newtids, function(tid, next) {
threadTools.privileges(tid, uid, function(err, privileges) {
- if (!err && privileges.read) {
- next(true);
- } else {
- next(false);
- }
+ next(!err && privileges.read);
});
}, function(newtids) {
unreadTids.push.apply(unreadTids, newtids);
@@ -692,9 +692,7 @@ var async = require('async'),
}
function hasReadTopic(next) {
- Topics.hasReadTopic(topicData.tid, current_user, function(hasRead) {
- next(null, hasRead);
- });
+ Topics.hasReadTopic(topicData.tid, current_user, next);
}
function getTeaserInfo(next) {
@@ -870,9 +868,7 @@ var async = require('async'),
function getReadStatus(next) {
if (uid && parseInt(uid, 10) > 0) {
- Topics.hasReadTopic(tid, uid, function(read) {
- next(null, read);
- });
+ Topics.hasReadTopic(tid, uid, next);
} else {
next(null, null);
}
@@ -989,7 +985,7 @@ var async = require('async'),
Topics.hasReadTopics = function(tids, uid, callback) {
if(!parseInt(uid, 10)) {
- return callback(tids.map(function() {
+ return callback(null, tids.map(function() {
return false;
}));
}
@@ -1000,25 +996,15 @@ var async = require('async'),
sets.push('tid:' + tids[i] + ':read_by_uid');
}
- db.isMemberOfSets(sets, uid, function(err, hasRead) {
- callback(hasRead);
- });
+ db.isMemberOfSets(sets, uid, callback);
};
Topics.hasReadTopic = function(tid, uid, callback) {
if(!parseInt(uid, 10)) {
- return callback(false);
+ return callback(null, false);
}
- db.isSetMember('tid:' + tid + ':read_by_uid', uid, function(err, hasRead) {
-
- if (err === null) {
- callback(hasRead);
- } else {
- console.log(err);
- callback(false);
- }
- });
+ db.isSetMember('tid:' + tid + ':read_by_uid', uid, callback);
};
Topics.getTeasers = function(tids, callback) {