From 29fd89407c2e9958d656302430134cbaaa9d23e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 24 Mar 2015 12:55:27 -0400 Subject: [PATCH] closes #2872 show the last posts content and user in topic feeds --- src/routes/feeds.js | 53 +++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/src/routes/feeds.js b/src/routes/feeds.js index 58d44cbce5..86d9cbb82d 100644 --- a/src/routes/feeds.js +++ b/src/routes/feeds.js @@ -212,47 +212,30 @@ function generateForTopics(options, set, req, res, next) { } function generateTopicsFeed(feedOptions, feedTopics, callback) { - var tids = feedTopics.map(function(topic) { - return topic ? topic.tid : null; - }); - - topics.getMainPids(tids, function(err, pids) { - if (err) { - return callback(err); - } - posts.getPostsFields(pids, ['content'], function(err, posts) { - if (err) { - return callback(err); - } - feedTopics.forEach(function(topic, index) { - if (topic && posts[index]) { - topic.mainPost = posts[index].content; - } - }); - - feedOptions.ttl = 60; - feedOptions.feed_url = nconf.get('url') + feedOptions.feed_url; - feedOptions.site_url = nconf.get('url') + feedOptions.site_url; + feedOptions.ttl = 60; + feedOptions.feed_url = nconf.get('url') + feedOptions.feed_url; + feedOptions.site_url = nconf.get('url') + feedOptions.site_url; - var feed = new rss(feedOptions); + var feed = new rss(feedOptions); - if (feedTopics.length > 0) { - feed.pubDate = new Date(parseInt(feedTopics[0].lastposttime, 10)).toUTCString(); - } + if (feedTopics.length > 0) { + feed.pubDate = new Date(parseInt(feedTopics[0].lastposttime, 10)).toUTCString(); + } - feedTopics.forEach(function(topicData) { - feed.item({ - title: topicData.title, - description: topicData.mainPost, - url: nconf.get('url') + '/topic/' + topicData.slug, - author: topicData.username, - date: new Date(parseInt(topicData.lastposttime, 10)).toUTCString() - }); + feedTopics.forEach(function(topicData) { + if (topicData && topicData.teaser && topicData.teaser.user) { + feed.item({ + title: topicData.title, + description: topicData.teaser.content, + url: nconf.get('url') + '/topic/' + topicData.slug, + author: topicData.teaser.user.username, + date: new Date(parseInt(topicData.lastposttime, 10)).toUTCString() }); - callback(null, feed); - }); + } }); + callback(null, feed); + } function generateForRecentPosts(req, res, next) {