fix first post loading when pagination is enabled

v1.18.x
barisusakli 10 years ago
parent cfcfc8e0b1
commit 6a837632fa

@ -14,11 +14,11 @@ define('forum/topic/posts', [
Posts.onNewPost = function(data) { Posts.onNewPost = function(data) {
var tid = ajaxify.variables.get('topic_id'); var tid = ajaxify.variables.get('topic_id');
if(data && data.posts && data.posts.length && parseInt(data.posts[0].tid, 10) !== parseInt(tid, 10)) { if (data && data.posts && data.posts.length && parseInt(data.posts[0].tid, 10) !== parseInt(tid, 10)) {
return; return;
} }
if(config.usePagination) { if (config.usePagination) {
return onNewPostPagination(data); return onNewPostPagination(data);
} }
@ -32,14 +32,11 @@ define('forum/topic/posts', [
function onNewPostPagination(data) { function onNewPostPagination(data) {
var posts = data.posts; var posts = data.posts;
socket.emit('topics.getPageCount', ajaxify.variables.get('topic_id'), function(err, newPageCount) { if (pagination.currentPage === pagination.pageCount) {
createNewPosts(data);
if (pagination.currentPage === pagination.pageCount) { } else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) {
createNewPosts(data); pagination.loadPage(pagination.pageCount);
} else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) { }
pagination.loadPage(pagination.pageCount);
}
});
} }
function createNewPosts(data, callback) { function createNewPosts(data, callback) {

@ -54,7 +54,7 @@ topicsController.get = function(req, res, next) {
var settings = results.settings; var settings = results.settings;
var postCount = parseInt(results.topic.postcount, 10); var postCount = parseInt(results.topic.postcount, 10);
var pageCount = Math.ceil((postCount - 1) / settings.postsPerPage); var pageCount = Math.max(1, Math.ceil((postCount - 1) / settings.postsPerPage));
if (utils.isNumber(req.params.post_index)) { if (utils.isNumber(req.params.post_index)) {
var url = ''; var url = '';

Loading…
Cancel
Save