mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +01:00
client/topics.js refactor
ability to dismiss all flags
This commit is contained in:
@@ -6,7 +6,9 @@ define('admin/manage/flags', ['forum/infinitescroll', 'admin/modules/selectable'
|
|||||||
|
|
||||||
Flags.init = function() {
|
Flags.init = function() {
|
||||||
$('.post-container .content img').addClass('img-responsive');
|
$('.post-container .content img').addClass('img-responsive');
|
||||||
|
|
||||||
handleDismiss();
|
handleDismiss();
|
||||||
|
handleDismissAll();
|
||||||
handleDelete();
|
handleDelete();
|
||||||
handleInfiniteScroll();
|
handleInfiniteScroll();
|
||||||
};
|
};
|
||||||
@@ -22,6 +24,18 @@ define('admin/manage/flags', ['forum/infinitescroll', 'admin/modules/selectable'
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleDismissAll() {
|
||||||
|
$('#dismissAll').on('click', function() {
|
||||||
|
socket.emit('admin.dismissAllFlags', function(err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.post-container').empty().text('No flagged posts!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function handleDelete() {
|
function handleDelete() {
|
||||||
$('.flags').on('click', '.delete', function() {
|
$('.flags').on('click', '.delete', function() {
|
||||||
var btn = $(this);
|
var btn = $(this);
|
||||||
|
|||||||
@@ -3,17 +3,16 @@
|
|||||||
|
|
||||||
/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */
|
/* globals define, app, templates, translator, socket, bootbox, config, ajaxify, RELATIVE_PATH, utils */
|
||||||
|
|
||||||
var dependencies = [
|
define('forum/topic', [
|
||||||
'forum/pagination',
|
'forum/pagination',
|
||||||
'forum/infinitescroll',
|
'forum/infinitescroll',
|
||||||
'forum/topic/threadTools',
|
'forum/topic/threadTools',
|
||||||
'forum/topic/postTools',
|
'forum/topic/postTools',
|
||||||
'forum/topic/events',
|
'forum/topic/events',
|
||||||
'forum/topic/browsing',
|
'forum/topic/browsing',
|
||||||
|
'forum/topic/posts',
|
||||||
'navigator'
|
'navigator'
|
||||||
];
|
], function(pagination, infinitescroll, threadTools, postTools, events, browsing, posts, navigator) {
|
||||||
|
|
||||||
define('forum/topic', dependencies, function(pagination, infinitescroll, threadTools, postTools, events, browsing, navigator) {
|
|
||||||
var Topic = {},
|
var Topic = {},
|
||||||
currentUrl = '';
|
currentUrl = '';
|
||||||
|
|
||||||
@@ -24,8 +23,6 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
app.removeAlert('bookmark');
|
app.removeAlert('bookmark');
|
||||||
|
|
||||||
events.removeListeners();
|
events.removeListeners();
|
||||||
|
|
||||||
socket.removeListener('event:new_post', onNewPost);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -42,9 +39,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
|
|
||||||
app.enterRoom('topic_' + tid);
|
app.enterRoom('topic_' + tid);
|
||||||
|
|
||||||
processPage($('.topic'));
|
posts.processPage($('.topic'));
|
||||||
|
|
||||||
showBottomPostBar();
|
|
||||||
|
|
||||||
postTools.init(tid, thread_state);
|
postTools.init(tid, thread_state);
|
||||||
threadTools.init(tid, thread_state);
|
threadTools.init(tid, thread_state);
|
||||||
@@ -52,20 +47,14 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
|
|
||||||
handleSorting();
|
handleSorting();
|
||||||
|
|
||||||
hidePostToolsForDeletedPosts();
|
|
||||||
|
|
||||||
enableInfiniteLoadingOrPagination();
|
enableInfiniteLoadingOrPagination();
|
||||||
|
|
||||||
addBlockQuoteHandler();
|
addBlockQuoteHandler();
|
||||||
|
|
||||||
addBlockquoteEllipses($('.topic .post-content > blockquote'));
|
|
||||||
|
|
||||||
handleBookmark(tid);
|
handleBookmark(tid);
|
||||||
|
|
||||||
navigator.init('.posts > .post-row', postCount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex);
|
navigator.init('.posts > .post-row', postCount, Topic.toTop, Topic.toBottom, Topic.navigatorCallback, Topic.calculateIndex);
|
||||||
|
|
||||||
setupSocketListeners();
|
|
||||||
|
|
||||||
$(window).on('scroll', updateTopicTitle);
|
$(window).on('scroll', updateTopicTitle);
|
||||||
|
|
||||||
$(window).trigger('action:topic.loaded');
|
$(window).trigger('action:topic.loaded');
|
||||||
@@ -73,12 +62,6 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
socket.emit('topics.enter', tid);
|
socket.emit('topics.enter', tid);
|
||||||
};
|
};
|
||||||
|
|
||||||
function setupSocketListeners() {
|
|
||||||
socket.removeListener('event:new_post', onNewPost);
|
|
||||||
|
|
||||||
socket.on('event:new_post', onNewPost);
|
|
||||||
}
|
|
||||||
|
|
||||||
Topic.toTop = function() {
|
Topic.toTop = function() {
|
||||||
navigator.scrollTop(0);
|
navigator.scrollTop(0);
|
||||||
};
|
};
|
||||||
@@ -133,31 +116,6 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBottomPostBar() {
|
|
||||||
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
|
|
||||||
$('.bottom-post-bar').removeClass('hide');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onNewPost(data) {
|
|
||||||
var tid = ajaxify.variables.get('topic_id');
|
|
||||||
if(data && data.posts && data.posts.length && parseInt(data.posts[0].tid, 10) !== parseInt(tid, 10)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.usePagination) {
|
|
||||||
return onNewPostPagination(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i=0; i<data.posts.length; ++i) {
|
|
||||||
var postcount = $('.user_postcount_' + data.posts[i].uid);
|
|
||||||
postcount.html(parseInt(postcount.html(), 10) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
createNewPosts(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function addBlockQuoteHandler() {
|
function addBlockQuoteHandler() {
|
||||||
$('#post-container').on('click', 'blockquote .toggle', function() {
|
$('#post-container').on('click', 'blockquote .toggle', function() {
|
||||||
var blockQuote = $(this).parent('blockquote');
|
var blockQuote = $(this).parent('blockquote');
|
||||||
@@ -168,18 +126,10 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBlockquoteEllipses(blockquotes) {
|
|
||||||
blockquotes.each(function() {
|
|
||||||
var $this = $(this);
|
|
||||||
if ($this.find(':hidden:not(br)').length && !$this.find('.toggle').length) {
|
|
||||||
$this.append('<i class="fa fa-angle-down pointer toggle"></i>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function enableInfiniteLoadingOrPagination() {
|
function enableInfiniteLoadingOrPagination() {
|
||||||
if(!config.usePagination) {
|
if(!config.usePagination) {
|
||||||
infinitescroll.init(loadMorePosts, $('#post-container .post-row[data-index="0"]').height());
|
infinitescroll.init(posts.loadMorePosts, $('#post-container .post-row[data-index="0"]').height());
|
||||||
} else {
|
} else {
|
||||||
navigator.hide();
|
navigator.hide();
|
||||||
|
|
||||||
@@ -187,11 +137,6 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hidePostToolsForDeletedPosts() {
|
|
||||||
$('#post-container li.deleted').each(function() {
|
|
||||||
postTools.toggle($(this).attr('data-pid'), true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTopicTitle() {
|
function updateTopicTitle() {
|
||||||
if($(window).scrollTop() > 50) {
|
if($(window).scrollTop() > 50) {
|
||||||
@@ -252,203 +197,6 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
|
|||||||
return index;
|
return index;
|
||||||
};
|
};
|
||||||
|
|
||||||
function onNewPostPagination(data) {
|
|
||||||
var posts = data.posts;
|
|
||||||
socket.emit('topics.getPageCount', ajaxify.variables.get('topic_id'), function(err, newPageCount) {
|
|
||||||
|
|
||||||
pagination.recreatePaginationLinks(newPageCount);
|
|
||||||
|
|
||||||
if (pagination.currentPage === pagination.pageCount) {
|
|
||||||
createNewPosts(data);
|
|
||||||
} 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) {
|
|
||||||
callback = callback || function() {};
|
|
||||||
if(!data || (data.posts && !data.posts.length)) {
|
|
||||||
return callback(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeAlreadyAddedPosts() {
|
|
||||||
data.posts = data.posts.filter(function(post) {
|
|
||||||
return $('#post-container li[data-pid="' + post.pid +'"]').length === 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var after = null,
|
|
||||||
before = null;
|
|
||||||
|
|
||||||
function findInsertionPoint() {
|
|
||||||
var firstPostTimestamp = parseInt(data.posts[0].timestamp, 10);
|
|
||||||
var firstPostVotes = parseInt(data.posts[0].votes, 10);
|
|
||||||
var firstPostIndex = parseInt(data.posts[0].index, 10);
|
|
||||||
|
|
||||||
var firstReply = $('#post-container li.post-row[data-index!="0"]').first();
|
|
||||||
var lastReply = $('#post-container li.post-row[data-index!="0"]').last();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
} 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 (firstPostIndex > parseInt(firstReply.attr('data-index'), 10)) {
|
|
||||||
before = firstReply;
|
|
||||||
} else if(firstPostIndex <= parseInt(firstReply.attr('data-index'), 10)) {
|
|
||||||
after = lastReply;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
removeAlreadyAddedPosts();
|
|
||||||
if(!data.posts.length) {
|
|
||||||
return callback(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
findInsertionPoint();
|
|
||||||
|
|
||||||
data.title = $('<div></div>').text(ajaxify.variables.get('topic_name')).html();
|
|
||||||
data.viewcount = ajaxify.variables.get('viewcount');
|
|
||||||
|
|
||||||
infinitescroll.parseAndTranslate('topic', 'posts', data, function(html) {
|
|
||||||
if(after) {
|
|
||||||
html.insertAfter(after);
|
|
||||||
} else if(before) {
|
|
||||||
// Save document height and position for future reference (about 5 lines down)
|
|
||||||
var height = $(document).height(),
|
|
||||||
scrollTop = $(document).scrollTop(),
|
|
||||||
originalPostEl = $('li[data-index="0"]');
|
|
||||||
|
|
||||||
// Insert the new post
|
|
||||||
html.insertBefore(before);
|
|
||||||
|
|
||||||
// If the user is not at the top of the page... (or reasonably so...)
|
|
||||||
if (scrollTop > originalPostEl.offset().top) {
|
|
||||||
// Now restore the relative position the user was on prior to new post insertion
|
|
||||||
$(document).scrollTop(scrollTop + ($(document).height() - height));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$('#post-container').append(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
html.hide().fadeIn('slow');
|
|
||||||
|
|
||||||
addBlockquoteEllipses(html.find('.post-content > blockquote'));
|
|
||||||
|
|
||||||
$(window).trigger('action:posts.loaded');
|
|
||||||
onNewPostsLoaded(html, data.posts);
|
|
||||||
callback(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onNewPostsLoaded(html, posts) {
|
|
||||||
|
|
||||||
var pids = [];
|
|
||||||
for(var i=0; i<posts.length; ++i) {
|
|
||||||
pids.push(posts[i].pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.emit('posts.getPrivileges', pids, function(err, privileges) {
|
|
||||||
if(err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i<pids.length; ++i) {
|
|
||||||
toggleModTools(pids[i], privileges[i]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
processPage(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
function processPage(element) {
|
|
||||||
app.createUserTooltips();
|
|
||||||
app.replaceSelfLinks(element.find('a'));
|
|
||||||
utils.addCommasToNumbers(element.find('.formatted-number'));
|
|
||||||
utils.makeNumbersHumanReadable(element.find('.human-readable-number'));
|
|
||||||
element.find('span.timeago').timeago();
|
|
||||||
element.find('.post-content img:not(.emoji)').addClass('img-responsive').each(function() {
|
|
||||||
var $this = $(this);
|
|
||||||
if (!$this.parent().is('a')) {
|
|
||||||
$this.wrap('<a href="' + $this.attr('src') + '" target="_blank">');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
postTools.updatePostCount();
|
|
||||||
showBottomPostBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleModTools(pid, privileges) {
|
|
||||||
var postEl = $('.post-row[data-pid="' + pid + '"]');
|
|
||||||
|
|
||||||
if (!privileges.editable) {
|
|
||||||
postEl.find('.edit, .delete, .purge').remove();
|
|
||||||
}
|
|
||||||
if (!privileges.move) {
|
|
||||||
postEl.find('.move').remove();
|
|
||||||
}
|
|
||||||
postEl.find('.reply, .quote').toggleClass('hidden', !$('.post_reply').length);
|
|
||||||
var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.uid, 10);
|
|
||||||
postEl.find('.chat, .flag').toggleClass('hidden', isSelfPost || !app.uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadMorePosts(direction) {
|
|
||||||
if (!$('#post-container').length || navigator.scrollActive) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var reverse = config.topicPostSort === 'newest_to_oldest' || config.topicPostSort === 'most_votes';
|
|
||||||
|
|
||||||
infinitescroll.calculateAfter(direction, '#post-container .post-row[data-index!="0"]', config.postsPerPage, reverse, function(after, offset, el) {
|
|
||||||
loadPostsAfter(after);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadPostsAfter(after) {
|
|
||||||
var tid = ajaxify.variables.get('topic_id');
|
|
||||||
if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="1"]').length)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var indicatorEl = $('.loading-indicator');
|
|
||||||
if (!indicatorEl.is(':animated')) {
|
|
||||||
indicatorEl.fadeIn();
|
|
||||||
}
|
|
||||||
|
|
||||||
infinitescroll.loadMore('topics.loadMore', {
|
|
||||||
tid: tid,
|
|
||||||
after: after
|
|
||||||
}, function (data, done) {
|
|
||||||
|
|
||||||
indicatorEl.fadeOut();
|
|
||||||
|
|
||||||
if (data && data.posts && data.posts.length) {
|
|
||||||
createNewPosts(data, function(postsCreated) {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
hidePostToolsForDeletedPosts();
|
|
||||||
} else {
|
|
||||||
socket.emit('topics.markAsRead', [tid]);
|
|
||||||
navigator.update();
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Topic;
|
return Topic;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,12 @@
|
|||||||
|
|
||||||
/* globals app, ajaxify, define, socket, translator, templates */
|
/* globals app, ajaxify, define, socket, translator, templates */
|
||||||
|
|
||||||
define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', 'forum/topic/threadTools'], function(browsing, postTools, threadTools) {
|
define('forum/topic/events', [
|
||||||
|
'forum/topic/browsing',
|
||||||
|
'forum/topic/postTools',
|
||||||
|
'forum/topic/threadTools',
|
||||||
|
'forum/topic/posts'
|
||||||
|
], function(browsing, postTools, threadTools, posts) {
|
||||||
|
|
||||||
var Events = {};
|
var Events = {};
|
||||||
|
|
||||||
@@ -41,6 +46,7 @@ define('forum/topic/events', ['forum/topic/browsing', 'forum/topic/postTools', '
|
|||||||
'posts.unvote': togglePostVote,
|
'posts.unvote': togglePostVote,
|
||||||
|
|
||||||
'event:new_notification': onNewNotification,
|
'event:new_notification': onNewNotification,
|
||||||
|
'event:new_post': posts.onNewPost,
|
||||||
|
|
||||||
'event:topic.notifyTyping': onNotifyTyping,
|
'event:topic.notifyTyping': onNotifyTyping,
|
||||||
'event:topic.stopNotifyTyping': onStopNotifyTyping
|
'event:topic.stopNotifyTyping': onStopNotifyTyping
|
||||||
|
|||||||
253
public/src/client/topic/posts.js
Normal file
253
public/src/client/topic/posts.js
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* globals config, app, ajaxify, define, socket, utils */
|
||||||
|
|
||||||
|
define('forum/topic/posts', [
|
||||||
|
'forum/pagination',
|
||||||
|
'forum/infinitescroll',
|
||||||
|
'forum/topic/postTools',
|
||||||
|
'navigator'
|
||||||
|
], function(pagination, infinitescroll, postTools, navigator) {
|
||||||
|
|
||||||
|
var Posts = {};
|
||||||
|
|
||||||
|
Posts.onNewPost = function(data) {
|
||||||
|
var tid = ajaxify.variables.get('topic_id');
|
||||||
|
if(data && data.posts && data.posts.length && parseInt(data.posts[0].tid, 10) !== parseInt(tid, 10)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(config.usePagination) {
|
||||||
|
return onNewPostPagination(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i=0; i<data.posts.length; ++i) {
|
||||||
|
var postcount = $('.user_postcount_' + data.posts[i].uid);
|
||||||
|
postcount.html(parseInt(postcount.html(), 10) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
createNewPosts(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
function onNewPostPagination(data) {
|
||||||
|
var posts = data.posts;
|
||||||
|
socket.emit('topics.getPageCount', ajaxify.variables.get('topic_id'), function(err, newPageCount) {
|
||||||
|
|
||||||
|
pagination.recreatePaginationLinks(newPageCount);
|
||||||
|
|
||||||
|
if (pagination.currentPage === pagination.pageCount) {
|
||||||
|
createNewPosts(data);
|
||||||
|
} 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) {
|
||||||
|
callback = callback || function() {};
|
||||||
|
if(!data || (data.posts && !data.posts.length)) {
|
||||||
|
return callback(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeAlreadyAddedPosts() {
|
||||||
|
data.posts = data.posts.filter(function(post) {
|
||||||
|
return $('#post-container li[data-pid="' + post.pid +'"]').length === 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var after = null,
|
||||||
|
before = null;
|
||||||
|
|
||||||
|
function findInsertionPoint() {
|
||||||
|
var firstPostTimestamp = parseInt(data.posts[0].timestamp, 10);
|
||||||
|
var firstPostVotes = parseInt(data.posts[0].votes, 10);
|
||||||
|
var firstPostIndex = parseInt(data.posts[0].index, 10);
|
||||||
|
|
||||||
|
var firstReply = $('#post-container li.post-row[data-index!="0"]').first();
|
||||||
|
var lastReply = $('#post-container li.post-row[data-index!="0"]').last();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} 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 (firstPostIndex > parseInt(firstReply.attr('data-index'), 10)) {
|
||||||
|
before = firstReply;
|
||||||
|
} else if(firstPostIndex <= parseInt(firstReply.attr('data-index'), 10)) {
|
||||||
|
after = lastReply;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeAlreadyAddedPosts();
|
||||||
|
if(!data.posts.length) {
|
||||||
|
return callback(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
findInsertionPoint();
|
||||||
|
|
||||||
|
data.title = $('<div></div>').text(ajaxify.variables.get('topic_name')).html();
|
||||||
|
data.viewcount = ajaxify.variables.get('viewcount');
|
||||||
|
|
||||||
|
infinitescroll.parseAndTranslate('topic', 'posts', data, function(html) {
|
||||||
|
if(after) {
|
||||||
|
html.insertAfter(after);
|
||||||
|
} else if(before) {
|
||||||
|
// Save document height and position for future reference (about 5 lines down)
|
||||||
|
var height = $(document).height(),
|
||||||
|
scrollTop = $(document).scrollTop(),
|
||||||
|
originalPostEl = $('li[data-index="0"]');
|
||||||
|
|
||||||
|
// Insert the new post
|
||||||
|
html.insertBefore(before);
|
||||||
|
|
||||||
|
// If the user is not at the top of the page... (or reasonably so...)
|
||||||
|
if (scrollTop > originalPostEl.offset().top) {
|
||||||
|
// Now restore the relative position the user was on prior to new post insertion
|
||||||
|
$(document).scrollTop(scrollTop + ($(document).height() - height));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$('#post-container').append(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
html.hide().fadeIn('slow');
|
||||||
|
|
||||||
|
$(window).trigger('action:posts.loaded');
|
||||||
|
onNewPostsLoaded(html, data.posts);
|
||||||
|
callback(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onNewPostsLoaded(html, posts) {
|
||||||
|
|
||||||
|
var pids = [];
|
||||||
|
for(var i=0; i<posts.length; ++i) {
|
||||||
|
pids.push(posts[i].pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.emit('posts.getPrivileges', pids, function(err, privileges) {
|
||||||
|
if(err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<pids.length; ++i) {
|
||||||
|
toggleModTools(pids[i], privileges[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Posts.processPage(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleModTools(pid, privileges) {
|
||||||
|
var postEl = $('.post-row[data-pid="' + pid + '"]');
|
||||||
|
|
||||||
|
if (!privileges.editable) {
|
||||||
|
postEl.find('.edit, .delete, .purge').remove();
|
||||||
|
}
|
||||||
|
if (!privileges.move) {
|
||||||
|
postEl.find('.move').remove();
|
||||||
|
}
|
||||||
|
postEl.find('.reply, .quote').toggleClass('hidden', !$('.post_reply').length);
|
||||||
|
var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.uid, 10);
|
||||||
|
postEl.find('.chat, .flag').toggleClass('hidden', isSelfPost || !app.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.loadMorePosts = function(direction) {
|
||||||
|
if (!$('#post-container').length || navigator.scrollActive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var reverse = config.topicPostSort === 'newest_to_oldest' || config.topicPostSort === 'most_votes';
|
||||||
|
|
||||||
|
infinitescroll.calculateAfter(direction, '#post-container .post-row[data-index!="0"]', config.postsPerPage, reverse, function(after, offset, el) {
|
||||||
|
loadPostsAfter(after);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function loadPostsAfter(after) {
|
||||||
|
var tid = ajaxify.variables.get('topic_id');
|
||||||
|
if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="1"]').length)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var indicatorEl = $('.loading-indicator');
|
||||||
|
if (!indicatorEl.is(':animated')) {
|
||||||
|
indicatorEl.fadeIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
infinitescroll.loadMore('topics.loadMore', {
|
||||||
|
tid: tid,
|
||||||
|
after: after
|
||||||
|
}, function (data, done) {
|
||||||
|
|
||||||
|
indicatorEl.fadeOut();
|
||||||
|
|
||||||
|
if (data && data.posts && data.posts.length) {
|
||||||
|
createNewPosts(data, function(postsCreated) {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
socket.emit('topics.markAsRead', [tid]);
|
||||||
|
navigator.update();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.processPage = function(element) {
|
||||||
|
app.createUserTooltips();
|
||||||
|
app.replaceSelfLinks(element.find('a'));
|
||||||
|
utils.addCommasToNumbers(element.find('.formatted-number'));
|
||||||
|
utils.makeNumbersHumanReadable(element.find('.human-readable-number'));
|
||||||
|
element.find('span.timeago').timeago();
|
||||||
|
element.find('.post-content img:not(.emoji)').addClass('img-responsive').each(function() {
|
||||||
|
var $this = $(this);
|
||||||
|
if (!$this.parent().is('a')) {
|
||||||
|
$this.wrap('<a href="' + $this.attr('src') + '" target="_blank">');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
postTools.updatePostCount();
|
||||||
|
addBlockquoteEllipses(element.find('.post-content > blockquote'));
|
||||||
|
hidePostToolsForDeletedPosts(element);
|
||||||
|
showBottomPostBar();
|
||||||
|
};
|
||||||
|
|
||||||
|
function showBottomPostBar() {
|
||||||
|
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
|
||||||
|
$('.bottom-post-bar').removeClass('hide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hidePostToolsForDeletedPosts(element) {
|
||||||
|
element.find('li.deleted').each(function() {
|
||||||
|
postTools.toggle($(this).attr('data-pid'), true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBlockquoteEllipses(blockquotes) {
|
||||||
|
blockquotes.each(function() {
|
||||||
|
var $this = $(this);
|
||||||
|
if ($this.find(':hidden:not(br)').length && !$this.find('.toggle').length) {
|
||||||
|
$this.append('<i class="fa fa-angle-down pointer toggle"></i>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Posts;
|
||||||
|
|
||||||
|
});
|
||||||
@@ -27,6 +27,9 @@ module.exports = function(Posts) {
|
|||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
removeFromCategoryRecentPosts(pid, postData.tid, next);
|
removeFromCategoryRecentPosts(pid, postData.tid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('posts:flagged', pid, next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
callback(err, postData);
|
callback(err, postData);
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ module.exports = function(Posts) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Posts.dismissAllFlags = function(callback) {
|
||||||
|
db.delete('posts:flagged', callback);
|
||||||
|
};
|
||||||
|
|
||||||
Posts.getFlags = function(uid, start, end, callback) {
|
Posts.getFlags = function(uid, start, end, callback) {
|
||||||
db.getSortedSetRevRange('posts:flagged', start, end, function(err, pids) {
|
db.getSortedSetRevRange('posts:flagged', start, end, function(err, pids) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -260,6 +260,10 @@ SocketAdmin.dismissFlag = function(socket, pid, callback) {
|
|||||||
posts.dismissFlag(pid, callback);
|
posts.dismissFlag(pid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketAdmin.dismissAllFlags = function(socket, data, callback) {
|
||||||
|
posts.dismissAllFlags(callback);
|
||||||
|
};
|
||||||
|
|
||||||
SocketAdmin.getMoreFlags = function(socket, after, callback) {
|
SocketAdmin.getMoreFlags = function(socket, after, callback) {
|
||||||
if (!parseInt(after, 10)) {
|
if (!parseInt(after, 10)) {
|
||||||
return callback('[[error:invalid-data]]');
|
return callback('[[error:invalid-data]]');
|
||||||
|
|||||||
@@ -41,6 +41,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-lg-3">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Flags Control Panel</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div>
|
||||||
|
<button class="btn btn-primary" id="dismissAll">Dismiss All</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user