From c74370bfb1627dd2cedfa6b9b24734a08ffd683a Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 26 Oct 2014 20:26:56 -0400 Subject: [PATCH] removed recent/day week month it starts with most recent 20 topics now and goes back instead of showing empty if there are no new replies in the past 24 hours --- public/src/client/recent.js | 30 +----------------------------- src/controllers/categories.js | 15 ++++++++++++--- src/routes/index.js | 2 +- src/socket.io/topics.js | 4 ++-- src/topics/recent.js | 15 +++++++++++++++ 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/public/src/client/recent.js b/public/src/client/recent.js index 78cbff6c14..054a087363 100644 --- a/public/src/client/recent.js +++ b/public/src/client/recent.js @@ -8,15 +8,6 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) { var newTopicCount = 0, newPostCount = 0; - var active = ''; - - function getActiveSection() { - var url = window.location.href, - parts = url.split('/'), - active = parts[parts.length - 1]; - return active; - } - $(window).on('action:ajaxify.start', function(ev, data) { if(data.url.indexOf('recent') !== 0) { Recent.removeListeners(); @@ -28,31 +19,13 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) { Recent.watchForNewPosts(); - active = Recent.selectActivePill(); - $('#new-topics-alert').on('click', function() { $(this).addClass('hide'); }); - infinitescroll.init(Recent.loadMoreTopics); }; - Recent.selectActivePill = function() { - var active = getActiveSection(); - - $('.nav-pills li').removeClass('active'); - $('.nav-pills li a').each(function() { - var $this = $(this); - if ($this.attr('href').match(active)) { - $this.parent().addClass('active'); - return false; - } - }); - - return active; - }; - Recent.watchForNewPosts = function () { newPostCount = 0; newTopicCount = 0; @@ -103,8 +76,7 @@ define('forum/recent', ['forum/infinitescroll'], function(infinitescroll) { } infinitescroll.loadMore('topics.loadMoreRecentTopics', { - after: $('#topics-container').attr('data-nextstart'), - term: active + after: $('#topics-container').attr('data-nextstart') }, function(data, done) { if (data.topics && data.topics.length) { Recent.onTopicsLoaded('recent', data.topics, false, done); diff --git a/src/controllers/categories.js b/src/controllers/categories.js index 6ade29e383..df08253d69 100644 --- a/src/controllers/categories.js +++ b/src/controllers/categories.js @@ -19,7 +19,7 @@ var apiToRegular = function(url) { categoriesController.recent = function(req, res, next) { var uid = req.user ? req.user.uid : 0; var end = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; - topics.getLatestTopics(uid, 0, end, req.params.term, function (err, data) { + topics.getRecentTopics(uid, 0, end, function (err, data) { if (err) { return next(err); } @@ -27,6 +27,9 @@ categoriesController.recent = function(req, res, next) { data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; plugins.fireHook('filter:category.get', data, uid, function(err, data) { + if (err) { + return next(err); + } res.render('recent', data); }); }); @@ -53,6 +56,9 @@ categoriesController.popular = function(req, res, next) { data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; plugins.fireHook('filter:category.get', {topics: data}, uid, function(err, data) { + if (err) { + return next(err); + } if (uid === 0) { anonCache[term] = data; lastUpdateTime = Date.now(); @@ -72,6 +78,9 @@ categoriesController.unread = function(req, res, next) { } plugins.fireHook('filter:category.get', data, uid, function(err, data) { + if (err) { + return next(err); + } res.render('unread', data); }); }); @@ -236,10 +245,10 @@ categoriesController.notFound = function(req, res) { categoriesController.notAllowed = function(req, res) { var uid = req.user ? req.user.uid : 0; - + if (uid) { if (res.locals.isAPI) { - res.status(403).json('not-allowed'); + res.status(403).json('not-allowed'); } else { res.status(403).render('403'); } diff --git a/src/routes/index.js b/src/routes/index.js index c8a8e4d59e..d7465d089d 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -50,7 +50,7 @@ function tagRoutes(app, middleware, controllers) { function categoryRoutes(app, middleware, controllers) { setupPageRoute(app, '/popular/:term?', middleware, [], controllers.categories.popular); - setupPageRoute(app, '/recent/:term?', middleware, [], controllers.categories.recent); + setupPageRoute(app, '/recent', middleware, [], controllers.categories.recent); setupPageRoute(app, '/unread', middleware, [middleware.authenticate], controllers.categories.unread); app.get('/api/unread/total', middleware.authenticate, controllers.categories.unreadTotal); diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index fdc0955f7c..2dae9af430 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -459,14 +459,14 @@ SocketTopics.loadMore = function(socket, data, callback) { }; SocketTopics.loadMoreRecentTopics = function(socket, data, callback) { - if(!data || !data.term || !data.after) { + if(!data || !data.after) { return callback(new Error('[[error:invalid-data]]')); } var start = parseInt(data.after, 10), end = start + 9; - topics.getLatestTopics(socket.uid, start, end, data.term, callback); + topics.getRecentTopics(socket.uid, start, end, callback); }; SocketTopics.loadMoreUnreadTopics = function(socket, data, callback) { diff --git a/src/topics/recent.js b/src/topics/recent.js index c8b6b551bc..a5692d4223 100644 --- a/src/topics/recent.js +++ b/src/topics/recent.js @@ -15,6 +15,21 @@ module.exports = function(Topics) { year: 31104000000 }; + Topics.getRecentTopics = function(uid, start, end, callback) { + async.waterfall([ + function(next) { + db.getSortedSetRevRange('topics:recent', start, end, next); + }, + function(tids, next) { + Topics.getTopics('topics:recent', uid, tids, next); + }, + function(data, next) { + data.nextStart = end + 1; + next(null, data); + } + ], callback); + }; + Topics.getLatestTopics = function(uid, start, end, term, callback) { Topics.getLatestTids(start, end, term, function(err, tids) { if (err) {