Node.js based forum software built for the modern web
closes #1679
barisusakli4c2765a79c98
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.jsindex 540550996f..1e28ddd970 100644--- a/public/src/forum/topic.js+++ b/public/src/forum/topic.js@@ -51,7 +51,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');var postIndex = getPostIndex();if (postIndex) {- Topic.scrollToPost(postIndex, true);+ Topic.scrollToPost(postIndex - 1, true);} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && postCount > 1) {app.alert({alert_id: 'bookmark',@@ -96,7 +96,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/function getPostIndex() {var parts = window.location.pathname.split('/');- return parts[4] ? (parseInt(parts[4], 10) - 1) : '';+ return parts[4] ? parseInt(parts[4], 10) : 0;}function showBottomPostBar() {@@ -194,7 +194,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/};Topic.scrollToPost = function(postIndex, highlight, duration, offset) {- if (!postIndex) {+ if (!utils.isNumber(postIndex)) {return;}diff --git a/public/src/modules/composer.js b/public/src/modules/composer.jsindex 95e39dc246..c24ec80d49 100644--- a/public/src/modules/composer.js+++ b/public/src/modules/composer.js@@ -151,7 +151,7 @@ define('composer', ['taskbar', 'composer/controls', 'composer/uploads', 'composetitle: threadData.title,body: threadData.body,modified: false,- isMain: !threadData.index,+ isMain: threadData.isMain,topic_thumb: threadData.topic_thumb,tags: threadData.tags});diff --git a/src/middleware/middleware.js b/src/middleware/middleware.jsindex 4c8b6a9e5f..bdcc74b69f 100644--- a/src/middleware/middleware.js+++ b/src/middleware/middleware.js@@ -88,7 +88,7 @@ middleware.checkPostIndex = function(req, res, next) {postCount = parseInt(postCount, 10) + 1;if (postIndex > postCount) {return res.locals.isAPI ? res.json(302, '/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount) : res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug + '/' + postCount);- } else if (postIndex <= 1) {+ } else if (postIndex < 1) {return res.locals.isAPI ? res.json(302, '/topic/' + req.params.topic_id + '/' + req.params.slug) : res.redirect('/topic/' + req.params.topic_id + '/' + req.params.slug);}next();diff --git a/src/posts.js b/src/posts.jsindex f368cae828..ec75efc126 100644--- a/src/posts.js+++ b/src/posts.js@@ -275,7 +275,7 @@ var async = require('async'),post.user = results.user;post.topic = results.topicCategory.topic;post.category = results.topicCategory.category;- post.index = parseInt(results.index, 10) + 1;+ post.index = results.index;if (stripTags) {var s = S(results.content);@@ -444,10 +444,13 @@ var async = require('async'),},function(result, next) {index = result;+ if (index === 1) {+ return callback(null, 1);+ }user.getSettings(uid, next);},function(settings, next) {- next(null, Math.ceil((index + 1) / settings.postsPerPage));+ next(null, Math.ceil((index - 1) / settings.postsPerPage));}], callback);};@@ -459,7 +462,10 @@ var async = require('async'),}db.sortedSetRank('tid:' + tid + ':posts', pid, function(err, index) {- callback(err, parseInt(index, 10) + 1);+ if (!utils.isNumber(index)) {+ return callback(err, 1);+ }+ callback(err, parseInt(index, 10) + 2);});});};diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 97f0803b30..f2084c5578 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -61,8 +61,8 @@ SocketModules.composer.push = function(socket, pid, callback) {tags: function(next) {topics.getTopicTags(postData.tid, next);},- index: function(next) {- posts.getPidIndex(pid, next);+ isMain: function(next) {+ postTools.isMain(pid, next);}}, function(err, results) {if(err) {@@ -75,7 +75,7 @@ SocketModules.composer.push = function(socket, pid, callback) {title: results.topic.title,topic_thumb: results.topic.thumb,tags: results.tags,- index: results.index+ isMain: results.isMain});});});diff --git a/src/socket.io/posts.js b/src/socket.io/posts.jsindex dfa1ceca9f..5ec2a6737f 100644--- a/src/socket.io/posts.js+++ b/src/socket.io/posts.js@@ -114,14 +114,9 @@ function sendNotificationToPostOwner(data, uid, notification) {return;}- var path = nconf.get('relative_path') + '/topic/' + results.slug;- if (parseInt(results.index, 10)) {- path += '/' + (parseInt(results.index, 10) + 1);- }-notifications.create({text: '[[' + notification + ', ' + results.username + ']]',- path: path,+ path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,uniqueId: 'post:' + data.pid,from: uid}, function(nid) {@@ -306,7 +301,7 @@ SocketPosts.flag = function(socket, pid, callback) {posts.getPidIndex(pid, next);},function(postIndex, next) {- path += '/' + (parseInt(postIndex, 10) + 1);+ path += '/' + postIndex;groups.get('administrators', {}, next);},function(adminGroup, next) {diff --git a/src/topics.js b/src/topics.jsindex d91e02f463..c0db6b4abd 100644--- a/src/topics.js+++ b/src/topics.js@@ -367,7 +367,7 @@ var async = require('async'),}results.postData.timestamp = utils.toISOString(results.postData.timestamp);- results.postData.index = parseInt(results.postIndex, 10) + 1;+ results.postData.index = results.postIndex;callback(null, results.postData);});diff --git a/src/topics/create.js b/src/topics/create.jsindex d6e4c8ccd9..cbaeec4947 100644--- a/src/topics/create.js+++ b/src/topics/create.js@@ -239,7 +239,7 @@ module.exports = function(Topics) {posts.getPidIndex(postData.pid, next);},function(index, next) {- postData.index = index;+ postData.index = index - 1;postData.favourited = false;postData.votes = 0;postData.display_moderator_tools = true;diff --git a/src/topics/follow.js b/src/topics/follow.jsindex 4c11430212..731963c623 100644--- a/src/topics/follow.js+++ b/src/topics/follow.js@@ -38,13 +38,9 @@ module.exports = function(Topics) {return next(err);}- var path = nconf.get('relative_path') + '/topic/' + results.topicData.slug;- if (parseInt(results.postIndex, 10)) {- path += '/' + (parseInt(results.postIndex, 10) + 1);- }notifications.create({text: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',- path: path,+ path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,uniqueId: 'topic:' + tid,from: exceptUid}, function(nid) {diff --git a/src/user/notifications.js b/src/user/notifications.jsindex 2fcd6f0924..2a6830c55a 100644--- a/src/user/notifications.js+++ b/src/user/notifications.js@@ -167,14 +167,9 @@ var async = require('async'),return;}- var message = '[[notifications:user_made_post, ' + results.username + ']]';- var path = nconf.get('relative_path') + '/topic/' + results.slug;- if (parseInt(results.postIndex, 10)) {- path += '/' + (parseInt(results.postIndex, 10) + 1);- }notifications.create({- text: message,- path: path,+ text: '[[notifications:user_made_post, ' + results.username + ']]',+ path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex,uniqueId: 'topic:' + tid,from: uid}, function(nid) {