deleted topic feed fix

v1.18.x
barisusakli 11 years ago
parent eeabae5738
commit 870bf95e5b

@ -56,7 +56,7 @@ topicsController.get = function(req, res, next) {
topics.getTopicWithPosts(tid, set, uid, start, end, reverse, function (err, topicData) {
if (topicData) {
if (parseInt(topicData.deleted, 10) === 1 && !userPrivileges.view_deleted) {
if (topicData.deleted && !userPrivileges.view_deleted) {
return next(new Error('[[error:no-topic]]'));
}
topicData.currentPage = page;

@ -40,45 +40,56 @@ function hasPrivileges(method, id, req, res, next) {
function generateForTopic(req, res, next) {
var tid = req.params.topic_id;
var uid = req.user ? req.user.uid : 0;
topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', uid, 0, 25, false, function (err, topicData) {
privileges.topics.get(tid, uid, function(err, userPrivileges) {
if (err) {
return next(err);
}
var description = topicData.posts.length ? topicData.posts[0].content : '';
var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
var author = topicData.posts.length ? topicData.posts[0].username : '';
var feed = new rss({
title: topicData.title,
description: description,
feed_url: nconf.get('url') + '/topic/' + tid + '.rss',
site_url: nconf.get('url') + '/topic/' + topicData.slug,
image_url: image_url,
author: author,
ttl: 60
}),
dateStamp;
if (topicData.posts.length > 0) {
feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
}
topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', uid, 0, 25, false, function (err, topicData) {
if (err) {
return next(err);
}
topicData.posts.forEach(function(postData) {
if (!postData.deleted) {
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
feed.item({
title: 'Reply to ' + topicData.title + ' on ' + dateStamp,
description: postData.content,
url: nconf.get('url') + '/topic/' + topicData.slug + '#' + postData.pid,
author: postData.username,
date: dateStamp
});
if (topicData.deleted && !userPrivileges.view_deleted) {
return res.redirect('404');
}
});
sendFeed(feed, res);
var description = topicData.posts.length ? topicData.posts[0].content : '';
var image_url = topicData.posts.length ? topicData.posts[0].picture : '';
var author = topicData.posts.length ? topicData.posts[0].username : '';
var feed = new rss({
title: topicData.title,
description: description,
feed_url: nconf.get('url') + '/topic/' + tid + '.rss',
site_url: nconf.get('url') + '/topic/' + topicData.slug,
image_url: image_url,
author: author,
ttl: 60
}),
dateStamp;
if (topicData.posts.length > 0) {
feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
}
topicData.posts.forEach(function(postData) {
if (!postData.deleted) {
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
feed.item({
title: 'Reply to ' + topicData.title + ' on ' + dateStamp,
description: postData.content,
url: nconf.get('url') + '/topic/' + topicData.slug + '#' + postData.pid,
author: postData.username,
date: dateStamp
});
}
});
sendFeed(feed, res);
});
});
}

Loading…
Cancel
Save