From bae76ebd704514e07b0716a113ac4888e28e1c4b Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 22 Feb 2014 00:49:32 -0500 Subject: [PATCH] fixed the redis error when going to unread/recent if nextStart is missing --- public/src/forum/unread.js | 1 + src/routes/api.js | 6 ++++++ src/topics.js | 28 ++++++++++------------------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js index 3ed2baf5cc..9829ca7a25 100644 --- a/public/src/forum/unread.js +++ b/public/src/forum/unread.js @@ -47,6 +47,7 @@ define(['forum/recent'], function(recent) { if(!$('#topics-container').length) { return; } + loadingMoreTopics = true; socket.emit('topics.loadMoreUnreadTopics', { after: $('#topics-container').attr('data-nextstart') diff --git a/src/routes/api.js b/src/routes/api.js index a89b61ed5b..7cdd7a8589 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -287,6 +287,9 @@ var path = require('path'), app.get('/unread', function (req, res, next) { var uid = (req.user) ? req.user.uid : 0; + if(!req.user) { + return res.json(403, 'not-allowed'); + } topics.getUnreadTopics(uid, 0, 19, function (err, data) { if(err) { return next(err); @@ -298,6 +301,9 @@ var path = require('path'), app.get('/unread/total', function (req, res, next) { var uid = (req.user) ? req.user.uid : 0; + if(!req.user) { + return res.json(403, 'not-allowed'); + } topics.getTotalUnread(uid, function (err, data) { if(err) { return next(err); diff --git a/src/topics.js b/src/topics.js index 2de59a0062..7e0362e2cd 100644 --- a/src/topics.js +++ b/src/topics.js @@ -445,7 +445,8 @@ var async = require('async'), function getTopics(set, uid, tids, callback) { var returnTopics = { - 'topics': [] + topics: [], + nextStart: 0 }; if (!tids || !tids.length) { @@ -571,18 +572,14 @@ var async = require('async'), }; Topics.getUnreadTopics = function(uid, start, stop, callback) { + var unreadTopics = { - 'show_markallread_button': 'show', - 'no_topics_message': 'hidden', - 'topics': [] + no_topics_message: '', + show_markallread_button: 'hidden', + nextStart : 0, + topics: [] }; - function noUnreadTopics() { - unreadTopics.no_topics_message = ''; - unreadTopics.show_markallread_button = 'hidden'; - callback(null, unreadTopics); - } - function sendUnreadTopics(topicIds) { Topics.getTopicsByTids(topicIds, 0, uid, function(err, topicData) { @@ -597,13 +594,8 @@ var async = require('async'), unreadTopics.topics = topicData; unreadTopics.nextStart = parseInt(rank, 10) + 1; - - if (!topicData || topicData.length === 0) { - unreadTopics.no_topics_message = ''; - } - if (uid === 0 || topicData.length === 0) { - unreadTopics.show_markallread_button = 'hidden'; - } + unreadTopics.no_topics_message = (!topicData || topicData.length === 0) ? '' : 'hidden'; + unreadTopics.show_markallread_button = topicData.length === 0 ? 'hidden' : ''; callback(null, unreadTopics); }); @@ -618,7 +610,7 @@ var async = require('async'), if (unreadTids.length) { sendUnreadTopics(unreadTids); } else { - noUnreadTopics(); + callback(null, unreadTopics); } }); };