mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-16 13:30:23 +01:00
closes #450
backup database before upgrade! upgrade script will take the first post of each topic and set the `mainPid` property on the topic. then it will remove that pid from the sorted sets for that topic, this was done to make alternative sorting work. added a new sorted set called `tid:<id>:posts:votes` that is used to sort topic posts by vote count, the original sorted set `tid:<id>:posts` is used to sort by oldest first or newest first. the main post is added to the returned posts array on topic load and is always at the top. theme changes are minimal just a few new data properties on the posts and the sorting dropdown. hopefully didn't miss anything too critical.
This commit is contained in:
@@ -40,6 +40,8 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
||||
threadTools.init(tid, thread_state);
|
||||
events.init();
|
||||
|
||||
handleSorting();
|
||||
|
||||
hidePostToolsForDeletedPosts();
|
||||
|
||||
enableInfiniteLoadingOrPagination();
|
||||
@@ -77,6 +79,21 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
||||
socket.emit('topics.increaseViewCount', tid);
|
||||
};
|
||||
|
||||
function handleSorting() {
|
||||
var threadSort = $('.thread-sort');
|
||||
threadSort.find('i').removeClass('fa-check');
|
||||
var currentSetting = threadSort.find('a[data-sort="' + config.topicPostSort + '"]');
|
||||
currentSetting.find('i').addClass('fa-check');
|
||||
|
||||
$('.thread-sort').on('click', 'a', function() {
|
||||
var newSetting = $(this).attr('data-sort');
|
||||
socket.emit('user.setTopicSort', newSetting, function(err) {
|
||||
config.topicPostSort = newSetting;
|
||||
ajaxify.go('topic/' + ajaxify.variables.get('topic_slug'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getPostIndex() {
|
||||
var parts = window.location.pathname.split('/');
|
||||
return parts[4] ? (parseInt(parts[4], 10) - 1) : '';
|
||||
@@ -122,7 +139,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
||||
|
||||
function enableInfiniteLoadingOrPagination() {
|
||||
if(!config.usePagination) {
|
||||
infinitescroll.init(loadMorePosts);
|
||||
infinitescroll.init(loadMorePosts, $('#post-container .post-row[data-index="0"]').height());
|
||||
} else {
|
||||
navigator.hide();
|
||||
|
||||
@@ -283,25 +300,36 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
||||
before = null;
|
||||
|
||||
function findInsertionPoint() {
|
||||
var firstPid = parseInt(data.posts[0].pid, 10);
|
||||
var firstPostTimestamp = parseInt(data.posts[0].timestamp, 10);
|
||||
var firstPostVotes = parseInt(data.posts[0].votes, 10);
|
||||
var firstPostPid = data.posts[0].pid;
|
||||
|
||||
$('#post-container li[data-pid]').each(function() {
|
||||
var $this = $(this);
|
||||
var firstReply = $('#post-container li.post-row[data-index!="0"]').first();
|
||||
var lastReply = $('#post-container li.post-row[data-index!="0"]').last();
|
||||
|
||||
if(firstPid > parseInt($this.attr('data-pid'), 10)) {
|
||||
after = $this;
|
||||
if(after.next().length && after.next().hasClass('post-bar')) {
|
||||
after = after.next();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
if (config.topicPostSort === 'oldest_to_newest') {
|
||||
if (firstPostTimestamp < parseInt(firstReply.attr('data-timestamp'), 10)) {
|
||||
before = firstReply;
|
||||
} else if(firstPostTimestamp >= parseInt(lastReply.attr('data-timestamp'), 10)) {
|
||||
after = lastReply;
|
||||
}
|
||||
});
|
||||
|
||||
if (!after) {
|
||||
var firstPost = $('#post-container .post-row').first();
|
||||
if(firstPid < parseInt(firstPost.attr('data-pid'), 10)) {
|
||||
before = firstPost;
|
||||
} else if(config.topicPostSort === 'newest_to_oldest') {
|
||||
if (firstPostTimestamp > parseInt(firstReply.attr('data-timestamp'), 10)) {
|
||||
before = firstReply;
|
||||
} else if(firstPostTimestamp <= parseInt(lastReply.attr('data-timestamp'), 10)) {
|
||||
after = lastReply;
|
||||
}
|
||||
} else if(config.topicPostSort === 'most_votes') {
|
||||
if (firstPostVotes > parseInt(firstReply.attr('data-votes'), 10)) {
|
||||
before = firstReply;
|
||||
} else if(firstPostVotes < parseInt(firstReply.attr('data-votes'), 10)) {
|
||||
after = lastReply;
|
||||
} else {
|
||||
if (firstPostPid > firstReply.attr('data-pid')) {
|
||||
before = firstReply;
|
||||
} else if(firstPostPid <= firstReply.attr('data-pid')) {
|
||||
after = lastReply;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,7 +401,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
||||
return;
|
||||
}
|
||||
|
||||
infinitescroll.calculateAfter(direction, '#post-container .post-row', config.postsPerPage, function(after, offset, el) {
|
||||
infinitescroll.calculateAfter(direction, '#post-container .post-row[data-index!="0"]', config.postsPerPage, function(after, offset, el) {
|
||||
loadPostsAfter(after, function() {
|
||||
if (direction < 0 && el) {
|
||||
Topic.scrollToPost(el.attr('data-index'), false, 0, offset);
|
||||
@@ -384,7 +412,7 @@ define('forum/topic', ['forum/pagination', 'forum/infinitescroll', 'forum/topic/
|
||||
|
||||
function loadPostsAfter(after, callback) {
|
||||
var tid = ajaxify.variables.get('topic_id');
|
||||
if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="0"]').length)) {
|
||||
if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="1"]').length)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user