From 852396e60ddd22c7430874999939c8f650e28e44 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 21 Sep 2017 13:50:24 -0400 Subject: [PATCH] closes #5903 --- src/controllers/recent.js | 9 ++++++++- src/routes/feeds.js | 31 +++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/controllers/recent.js b/src/controllers/recent.js index 0849c4f576..7d95c2db2b 100644 --- a/src/controllers/recent.js +++ b/src/controllers/recent.js @@ -22,7 +22,7 @@ recentController.get = function (req, res, next) { var cid = req.query.cid; var filter = req.params.filter || ''; var categoryData; - + var rssToken; if (!validFilter[filter]) { return next(); } @@ -36,9 +36,13 @@ recentController.get = function (req, res, next) { watchedCategories: function (next) { helpers.getWatchedCategories(req.uid, cid, next); }, + rssToken: function (next) { + user.auth.getFeedToken(req.uid, next); + }, }, next); }, function (results, next) { + rssToken = results.rssToken; settings = results.settings; categoryData = results.watchedCategories; @@ -54,6 +58,9 @@ recentController.get = function (req, res, next) { data.set = 'topics:recent'; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; data.rssFeedUrl = nconf.get('relative_path') + '/recent.rss'; + if (req.uid) { + data.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken; + } data.title = '[[pages:recent]]'; data.filters = [{ name: '[[unread:all-topics]]', diff --git a/src/routes/feeds.js b/src/routes/feeds.js index 4cfa52c373..5aaf3590c2 100644 --- a/src/routes/feeds.js +++ b/src/routes/feeds.js @@ -185,13 +185,28 @@ function generateForRecent(req, res, next) { if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) { return controllers404.send404(req, res); } - generateForTopics({ - uid: req.uid, - title: 'Recently Active Topics', - description: 'A list of topics that have been active within the past 24 hours', - feed_url: '/recent.rss', - site_url: '/recent', - }, 'topics:recent', req, res, next); + + async.waterfall([ + function (next) { + if (req.query.token && req.query.uid) { + db.getObjectField('user:' + req.query.uid, 'rss_token', next); + } else { + next(null, null); + } + }, + function (token, next) { + next(null, token && token === req.query.token ? req.query.uid : req.uid); + }, + function (uid, next) { + generateForTopics({ + uid: uid, + title: 'Recently Active Topics', + description: 'A list of topics that have been active within the past 24 hours', + feed_url: '/recent.rss', + site_url: '/recent', + }, 'topics:recent', req, res, next); + }, + ], next); } function generateForPopular(req, res, next) { @@ -230,7 +245,7 @@ function generateForTopics(options, set, req, res, next) { var stop = options.hasOwnProperty('stop') ? options.stop : 19; async.waterfall([ function (next) { - topics.getTopicsFromSet(set, req.uid, start, stop, next); + topics.getTopicsFromSet(set, options.uid, start, stop, next); }, function (data, next) { generateTopicsFeed(options, data.topics, next);