v1.18.x
barisusakli 11 years ago
parent ce1934e566
commit 4c2765a79c

@ -51,7 +51,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark'); var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
var postIndex = getPostIndex(); var postIndex = getPostIndex();
if (postIndex) { if (postIndex) {
Topic.scrollToPost(postIndex, true); Topic.scrollToPost(postIndex - 1, true);
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && postCount > 1) { } else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && postCount > 1) {
app.alert({ app.alert({
alert_id: 'bookmark', alert_id: 'bookmark',
@ -96,7 +96,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
function getPostIndex() { function getPostIndex() {
var parts = window.location.pathname.split('/'); var parts = window.location.pathname.split('/');
return parts[4] ? (parseInt(parts[4], 10) - 1) : ''; return parts[4] ? parseInt(parts[4], 10) : 0;
} }
function showBottomPostBar() { function showBottomPostBar() {
@ -194,7 +194,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
}; };
Topic.scrollToPost = function(postIndex, highlight, duration, offset) { Topic.scrollToPost = function(postIndex, highlight, duration, offset) {
if (!postIndex) { if (!utils.isNumber(postIndex)) {
return; return;
} }

@ -151,7 +151,7 @@ define('composer', ['taskbar', 'composer/controls', 'composer/uploads', 'compose
title: threadData.title, title: threadData.title,
body: threadData.body, body: threadData.body,
modified: false, modified: false,
isMain: !threadData.index, isMain: threadData.isMain,
topic_thumb: threadData.topic_thumb, topic_thumb: threadData.topic_thumb,
tags: threadData.tags tags: threadData.tags
}); });

@ -88,7 +88,7 @@ middleware.checkPostIndex = function(req, res, next) {
postCount = parseInt(postCount, 10) + 1; postCount = parseInt(postCount, 10) + 1;
if (postIndex > postCount) { 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); 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); 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(); next();

@ -275,7 +275,7 @@ var async = require('async'),
post.user = results.user; post.user = results.user;
post.topic = results.topicCategory.topic; post.topic = results.topicCategory.topic;
post.category = results.topicCategory.category; post.category = results.topicCategory.category;
post.index = parseInt(results.index, 10) + 1; post.index = results.index;
if (stripTags) { if (stripTags) {
var s = S(results.content); var s = S(results.content);
@ -444,10 +444,13 @@ var async = require('async'),
}, },
function(result, next) { function(result, next) {
index = result; index = result;
if (index === 1) {
return callback(null, 1);
}
user.getSettings(uid, next); user.getSettings(uid, next);
}, },
function(settings, next) { function(settings, next) {
next(null, Math.ceil((index + 1) / settings.postsPerPage)); next(null, Math.ceil((index - 1) / settings.postsPerPage));
} }
], callback); ], callback);
}; };
@ -459,7 +462,10 @@ var async = require('async'),
} }
db.sortedSetRank('tid:' + tid + ':posts', pid, function(err, index) { 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);
}); });
}); });
}; };

@ -61,8 +61,8 @@ SocketModules.composer.push = function(socket, pid, callback) {
tags: function(next) { tags: function(next) {
topics.getTopicTags(postData.tid, next); topics.getTopicTags(postData.tid, next);
}, },
index: function(next) { isMain: function(next) {
posts.getPidIndex(pid, next); postTools.isMain(pid, next);
} }
}, function(err, results) { }, function(err, results) {
if(err) { if(err) {
@ -75,7 +75,7 @@ SocketModules.composer.push = function(socket, pid, callback) {
title: results.topic.title, title: results.topic.title,
topic_thumb: results.topic.thumb, topic_thumb: results.topic.thumb,
tags: results.tags, tags: results.tags,
index: results.index isMain: results.isMain
}); });
}); });
}); });

@ -114,14 +114,9 @@ function sendNotificationToPostOwner(data, uid, notification) {
return; return;
} }
var path = nconf.get('relative_path') + '/topic/' + results.slug;
if (parseInt(results.index, 10)) {
path += '/' + (parseInt(results.index, 10) + 1);
}
notifications.create({ notifications.create({
text: '[[' + notification + ', ' + results.username + ']]', text: '[[' + notification + ', ' + results.username + ']]',
path: path, path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.index,
uniqueId: 'post:' + data.pid, uniqueId: 'post:' + data.pid,
from: uid from: uid
}, function(nid) { }, function(nid) {
@ -306,7 +301,7 @@ SocketPosts.flag = function(socket, pid, callback) {
posts.getPidIndex(pid, next); posts.getPidIndex(pid, next);
}, },
function(postIndex, next) { function(postIndex, next) {
path += '/' + (parseInt(postIndex, 10) + 1); path += '/' + postIndex;
groups.get('administrators', {}, next); groups.get('administrators', {}, next);
}, },
function(adminGroup, next) { function(adminGroup, next) {

@ -367,7 +367,7 @@ var async = require('async'),
} }
results.postData.timestamp = utils.toISOString(results.postData.timestamp); 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); callback(null, results.postData);
}); });

@ -239,7 +239,7 @@ module.exports = function(Topics) {
posts.getPidIndex(postData.pid, next); posts.getPidIndex(postData.pid, next);
}, },
function(index, next) { function(index, next) {
postData.index = index; postData.index = index - 1;
postData.favourited = false; postData.favourited = false;
postData.votes = 0; postData.votes = 0;
postData.display_moderator_tools = true; postData.display_moderator_tools = true;

@ -38,13 +38,9 @@ module.exports = function(Topics) {
return next(err); 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({ notifications.create({
text: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', 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, uniqueId: 'topic:' + tid,
from: exceptUid from: exceptUid
}, function(nid) { }, function(nid) {

@ -167,14 +167,9 @@ var async = require('async'),
return; 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({ notifications.create({
text: message, text: '[[notifications:user_made_post, ' + results.username + ']]',
path: path, path: nconf.get('relative_path') + '/topic/' + results.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid, uniqueId: 'topic:' + tid,
from: uid from: uid
}, function(nid) { }, function(nid) {

Loading…
Cancel
Save