@@ -44,7 +44,7 @@
-
{topic_name}
+ {title}
diff --git a/src/categories.js b/src/categories.js
index 5eafaff6cb..577fa61fac 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -59,39 +59,27 @@ var db = require('./database'),
Categories.markAsRead(cid, uid);
}
- function getCategoryData(next) {
- Categories.getCategoryData(cid, next);
- }
-
- function getTopics(next) {
- Categories.getCategoryTopics(cid, start, end, uid, next);
- }
-
- function getPageCount(next) {
- Categories.getPageCount(cid, uid, next);
- }
-
async.parallel({
- 'category': getCategoryData,
- 'topics': getTopics,
- 'pageCount': getPageCount
+ category: function(next) {
+ Categories.getCategoryData(cid, next);
+ },
+ topics : function(next) {
+ Categories.getCategoryTopics(cid, start, end, uid, next);
+ },
+ pageCount: function(next) {
+ Categories.getPageCount(cid, uid, next);
+ }
}, function(err, results) {
if(err) {
return callback(err);
}
- var category = {
- 'category_name': results.category.name,
- 'category_description': results.category.description,
- 'link': results.category.link,
- 'disabled': results.category.disabled,
- 'topic_row_size': 'col-md-9',
- 'category_id': cid,
- 'topics': results.topics.topics,
- 'nextStart': results.topics.nextStart,
- 'pageCount': results.pageCount,
- 'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
- };
+ var category = results.category;
+ category.topics = results.topics.topics;
+ category.nextStart = results.topics.nextStart;
+ category.pageCount = results.pageCount;
+ category.disableSocialButtons = meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false;
+ category.topic_row_size = 'col-md-9';
callback(null, category);
});
diff --git a/src/routes/api.js b/src/routes/api.js
index 7cdd7a8589..89ec9fe2f4 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -169,7 +169,8 @@ var path = require('path'),
});
app.get('/topic/:id/:slug?', function (req, res, next) {
- var uid = (req.user) ? req.user.uid : 0;
+ var uid = req.user? parseInt(req.user.uid, 10) : 0;
+ var tid = req.params.id;
var page = 1;
if(req.query && req.query.page) {
page = req.query.page;
@@ -187,29 +188,41 @@ var path = require('path'),
var start = (page - 1) * settings.postsPerPage;
var end = start + settings.postsPerPage - 1;
- ThreadTools.privileges(req.params.id, uid, function(err, privileges) {
- if (privileges.read) {
- topics.getTopicWithPosts(req.params.id, uid, start, end, false, function (err, data) {
- if(err) {
- return next(err);
- }
+ ThreadTools.privileges(tid, uid, function(err, privileges) {
+ if(err) {
+ return next(err);
+ }
- if(page > data.pageCount) {
- return res.send(404);
- }
+ if(!privileges.read) {
+ res.send(403);
+ }
- data.currentPage = page;
- data.privileges = privileges;
+ topics.getTopicWithPosts(tid, uid, start, end, function (err, data) {
+ if(err) {
+ return next(err);
+ }
- if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
- return res.json(404, {});
- }
+ if(page > data.pageCount) {
+ return res.send(404);
+ }
- res.json(data);
- });
- } else {
- res.send(403);
- }
+ if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
+ return res.json(404, {});
+ }
+
+ data.currentPage = page;
+ data.privileges = privileges;
+
+ if (uid) {
+ topics.markAsRead(tid, uid, function(err) {
+ topics.pushUnreadCount(uid);
+ });
+ }
+
+ topics.increaseViewCount(tid);
+
+ res.json(data);
+ });
});
});
});
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index 1b18024742..e377614fb0 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -55,7 +55,7 @@
function generateForTopic(req, res, next) {
var tid = req.params.topic_id;
- topics.getTopicWithPosts(tid, 0, 0, 25, true, function (err, topicData) {
+ topics.getTopicWithPosts(tid, 0, 0, 25, function (err, topicData) {
if (err) {
return next(err);
}
@@ -65,7 +65,7 @@
var author = topicData.posts.length ? topicData.posts[0].username : '';
var feed = new rss({
- title: topicData.topic_name,
+ title: topicData.title,
description: description,
feed_url: nconf.get('url') + '/topic/' + tid + '.rss',
site_url: nconf.get('url') + '/topic/' + topicData.slug,
@@ -85,7 +85,7 @@
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
feed.item({
- title: 'Reply to ' + topicData.topic_name + ' on ' + dateStamp,
+ title: 'Reply to ' + topicData.title + ' on ' + dateStamp,
description: postData.content,
url: nconf.get('url') + '/topic/' + topicData.slug + '#' + postData.pid,
author: postData.username,
@@ -109,10 +109,10 @@
}
var feed = new rss({
- title: categoryData.category_name,
- description: categoryData.category_description,
+ title: categoryData.name,
+ description: categoryData.description,
feed_url: nconf.get('url') + '/category/' + cid + '.rss',
- site_url: nconf.get('url') + '/category/' + categoryData.category_id,
+ site_url: nconf.get('url') + '/category/' + categoryData.cid,
ttl: 60
});
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 049735b71c..dcbf85daa1 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -217,7 +217,6 @@ SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
callback(null, "");
}
- console.log(data);
var max = 5; //hardcoded
var usernames = "";
diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js
index 0950e9fd6c..e96fc2611d 100644
--- a/src/socket.io/topics.js
+++ b/src/socket.io/topics.js
@@ -247,7 +247,7 @@ SocketTopics.loadMore = function(socket, data, callback) {
async.parallel({
posts: function(next) {
- topics.getTopicPosts(data.tid, start, end, socket.uid, next);
+ topics.getTopicPosts(data.tid, start, end, socket.uid, false, next);
},
privileges: function(next) {
threadTools.privileges(data.tid, socket.uid, next);
diff --git a/src/topics.js b/src/topics.js
index fe062b8b52..328f50ae9f 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -634,7 +634,7 @@ var async = require('async'),
});
};
- Topics.getTopicsByTids = function(tids, cid, current_user, callback) {
+ Topics.getTopicsByTids = function(tids, cid, uid, callback) {
if (!Array.isArray(tids) || tids.length === 0) {
return callback(null, []);
@@ -643,13 +643,13 @@ var async = require('async'),
function getTopicInfo(topicData, callback) {
async.parallel({
hasread : function (next) {
- Topics.hasReadTopic(topicData.tid, current_user, next);
+ Topics.hasReadTopic(topicData.tid, uid, next);
},
teaser : function (next) {
Topics.getTeaser(topicData.tid, next);
},
privileges : function (next) {
- categoryTools.privileges(topicData.cid, current_user, next);
+ categoryTools.privileges(topicData.cid, uid, next);
},
categoryData : function (next) {
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon'], next);
@@ -660,7 +660,7 @@ var async = require('async'),
function isTopicVisible(topicData, topicInfo) {
var deleted = parseInt(topicData.deleted, 10) !== 0;
- return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(current_user, 10);
+ return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(uid, 10);
}
function loadTopic(tid, next) {
@@ -686,7 +686,7 @@ var async = require('async'),
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
topicData.locked = parseInt(topicData.locked, 10) === 1;
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
- topicData.unread = !(topicInfo.hasread && parseInt(current_user, 10) !== 0);
+ topicData.unread = !(topicInfo.hasread && parseInt(uid, 10) !== 0);
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
topicData.category = topicInfo.categoryData;
@@ -710,78 +710,47 @@ var async = require('async'),
});
};
- Topics.getTopicWithPosts = function(tid, current_user, start, end, quiet, callback) {
+ Topics.getTopicWithPosts = function(tid, uid, start, end, callback) {
threadTools.exists(tid, function(err, exists) {
if (err || !exists) {
return callback(err || new Error('Topic tid \'' + tid + '\' not found'));
}
- // "quiet" is used for things like RSS feed updating, HTML parsing for non-js users, etc
- if (!quiet) {
- Topics.markAsRead(tid, current_user, function(err) {
- Topics.pushUnreadCount(current_user);
- });
- Topics.increaseViewCount(tid);
- }
-
- function getTopicData(next) {
- Topics.getTopicData(tid, next);
- }
-
- function getTopicPosts(next) {
- Topics.getTopicPosts(tid, start, end, current_user, false, next);
- }
-
- function getPrivileges(next) {
- threadTools.privileges(tid, current_user, next);
- }
-
- function getCategoryData(next) {
- Topics.getCategoryData(tid, next);
- }
-
- function getPageCount(next) {
- Topics.getPageCount(tid, current_user, next);
- }
-
- function getThreadTools(next) {
- Plugins.fireHook('filter:topic.thread_tools', [], function(err, threadTools) {
- next(err, threadTools);
- });
- }
-
- async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData, getPageCount, getThreadTools], function(err, results) {
+ async.parallel({
+ topicData : function(next) {
+ Topics.getTopicData(tid, next);
+ },
+ posts : function(next) {
+ Topics.getTopicPosts(tid, start, end, uid, false, next);
+ },
+ privileges : function(next) {
+ threadTools.privileges(tid, uid, next);
+ },
+ category : function(next) {
+ Topics.getCategoryData(tid, next);
+ },
+ pageCount : function(next) {
+ Topics.getPageCount(tid, uid, next);
+ },
+ threadTools : function(next) {
+ Plugins.fireHook('filter:topic.thread_tools', [], next);
+ }
+ }, function(err, results) {
if (err) {
winston.error('[Topics.getTopicWithPosts] Could not retrieve topic data: ', err.message);
return callback(err);
}
- var topicData = results[0],
- privileges = results[2],
- categoryData = results[3],
- pageCount = results[4],
- threadTools = results[5];
-
- callback(null, {
- 'topic_name': topicData.title,
- 'category_name': categoryData.name,
- 'category_slug': categoryData.slug,
- 'locked': topicData.locked,
- 'deleted': topicData.deleted,
- 'pinned': topicData.pinned,
- 'timestamp': topicData.timestamp,
- 'slug': topicData.slug,
- 'thumb': topicData.thumb,
- 'postcount': topicData.postcount,
- 'viewcount': topicData.viewcount,
- 'pageCount': pageCount,
- 'unreplied': parseInt(topicData.postcount, 10) === 1,
- 'topic_id': tid,
- 'expose_tools': privileges.editable ? 1 : 0,
- 'thread_tools': threadTools,
- 'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
- 'posts': results[1]
- });
+ var topicData = results.topicData;
+ topicData.category = results.category;
+ topicData.posts = results.posts;
+ topicData.thread_tools = results.threadTools;
+ topicData.pageCount = results.pageCount;
+ topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
+ topicData.expose_tools = results.privileges.editable ? 1 : 0;
+ topicData.disableSocialButtons = meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false;
+
+ callback(null, topicData);
});
});
};
diff --git a/src/webserver.js b/src/webserver.js
index 9999c1a22e..1fe43f5743 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -596,7 +596,7 @@ process.on('uncaughtException', function(err) {
var start = (page - 1) * settings.topicsPerPage,
end = start + settings.topicsPerPage - 1;
- topics.getTopicWithPosts(tid, uid, start, end, true, function (err, topicData) {
+ topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
if (topicData) {
if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) {
return next(new Error('Topic deleted'), null);
@@ -642,7 +642,7 @@ process.on('uncaughtException', function(err) {
metaTags: [
{
name: "title",
- content: topicData.topic_name
+ content: topicData.title
},
{
name: "description",
@@ -650,7 +650,7 @@ process.on('uncaughtException', function(err) {
},
{
property: 'og:title',
- content: topicData.topic_name
+ content: topicData.title
},
{
property: 'og:description',
@@ -682,7 +682,7 @@ process.on('uncaughtException', function(err) {
},
{
property: 'article:section',
- content: topicData.category_name
+ content: topicData.category.name
}
],
linkTags: [
@@ -693,7 +693,7 @@ process.on('uncaughtException', function(err) {
},
{
rel: 'up',
- href: nconf.get('url') + '/category/' + topicData.category_slug
+ href: nconf.get('url') + '/category/' + topicData.category.slug
}
]
}, function (err, header) {
@@ -783,15 +783,15 @@ process.on('uncaughtException', function(err) {
metaTags: [
{
name: 'title',
- content: categoryData.category_name
+ content: categoryData.name
},
{
property: 'og:title',
- content: categoryData.category_name
+ content: categoryData.name
},
{
name: 'description',
- content: categoryData.category_description
+ content: categoryData.description
},
{
property: "og:type",
diff --git a/tests/categories.js b/tests/categories.js
index 770ad0b498..1c1e1fac32 100644
--- a/tests/categories.js
+++ b/tests/categories.js
@@ -33,8 +33,8 @@ describe('Categories', function() {
it('should retrieve a newly created category by its ID', function(done) {
Categories.getCategoryById(categoryObj.cid, 0, -1, 0, function(err, categoryData) {
assert(categoryData);
- assert.equal(categoryObj.name, categoryData.category_name);
- assert.equal(categoryObj.description, categoryData.category_description);
+ assert.equal(categoryObj.name, categoryData.name);
+ assert.equal(categoryObj.description, categoryData.description);
done();
});