mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
replies to posts
This commit is contained in:
@@ -25,14 +25,7 @@ define('forum/topic/posts', [
|
||||
|
||||
data.loggedIn = app.user.uid ? true : false;
|
||||
data.privileges = ajaxify.data.privileges;
|
||||
data.posts.forEach(function (post) {
|
||||
post.selfPost = !!app.user.uid && parseInt(post.uid, 10) === parseInt(app.user.uid, 10);
|
||||
post.display_edit_tools = (ajaxify.data.privileges['posts:edit'] && post.selfPost) || ajaxify.data.privileges.isAdminOrMod;
|
||||
post.display_delete_tools = (ajaxify.data.privileges['posts:delete'] && post.selfPost) || ajaxify.data.privileges.isAdminOrMod;
|
||||
post.display_moderator_tools = post.display_edit_tools || post.display_delete_tools;
|
||||
post.display_move_tools = ajaxify.data.privileges.isAdminOrMod;
|
||||
post.display_post_menu = ajaxify.data.privileges.isAdminOrMod || (post.selfPost && !ajaxify.data.locked) || ((app.user.uid || ajaxify.data.postSharing.length) && !post.deleted);
|
||||
});
|
||||
Posts.modifyPostsByPrivileges(data.posts);
|
||||
|
||||
updatePostCounts(data.posts);
|
||||
|
||||
@@ -46,6 +39,17 @@ define('forum/topic/posts', [
|
||||
}
|
||||
};
|
||||
|
||||
Posts.modifyPostsByPrivileges = function (posts) {
|
||||
posts.forEach(function (post) {
|
||||
post.selfPost = !!app.user.uid && parseInt(post.uid, 10) === parseInt(app.user.uid, 10);
|
||||
post.display_edit_tools = (ajaxify.data.privileges['posts:edit'] && post.selfPost) || ajaxify.data.privileges.isAdminOrMod;
|
||||
post.display_delete_tools = (ajaxify.data.privileges['posts:delete'] && post.selfPost) || ajaxify.data.privileges.isAdminOrMod;
|
||||
post.display_moderator_tools = post.display_edit_tools || post.display_delete_tools;
|
||||
post.display_move_tools = ajaxify.data.privileges.isAdminOrMod;
|
||||
post.display_post_menu = ajaxify.data.privileges.isAdminOrMod || (post.selfPost && !ajaxify.data.locked) || ((app.user.uid || ajaxify.data.postSharing.length) && !post.deleted);
|
||||
});
|
||||
};
|
||||
|
||||
function updatePostCounts(posts) {
|
||||
for (var i = 0; i < posts.length; ++i) {
|
||||
var cmp = components.get('user/postcount', posts[i].uid);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
/* globals define, app, ajaxify, bootbox, socket, templates, utils, config */
|
||||
/* globals define, app, ajaxify, socket */
|
||||
|
||||
define('forum/topic/replies', ['navigator', 'components', 'translator'], function (navigator, components, translator) {
|
||||
define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'], function (navigator, components, posts) {
|
||||
|
||||
var Replies = {};
|
||||
|
||||
@@ -19,7 +19,7 @@ define('forum/topic/replies', ['navigator', 'components', 'translator'], functio
|
||||
}
|
||||
|
||||
function onRepliesClicked(button, tid) {
|
||||
var post = button.parents('[data-pid]');
|
||||
var post = button.closest('[data-pid]');
|
||||
var pid = post.data('pid');
|
||||
var open = button.children('[component="post/replies/open"]');
|
||||
var loading = button.children('[component="post/replies/loading"]');
|
||||
@@ -40,16 +40,20 @@ define('forum/topic/replies', ['navigator', 'components', 'translator'], functio
|
||||
loading.addClass('hidden');
|
||||
close.removeClass('hidden');
|
||||
|
||||
templates.parse('partials/posts_list', data, function (html) {
|
||||
translator.translate(html, function (translated) {
|
||||
$('<div>', {component: 'post/replies'}).html(translated).hide().insertAfter(button).slideDown('fast');
|
||||
});
|
||||
posts.modifyPostsByPrivileges(data);
|
||||
var tplData ={
|
||||
posts: data,
|
||||
privileges: ajaxify.data.privileges,
|
||||
loggedIn: !!app.user.uid,
|
||||
hideReplies: true
|
||||
};
|
||||
app.parseAndTranslate('topic', 'posts', tplData, function (html) {
|
||||
$('<div>', {component: 'post/replies'}).html(html).hide().insertAfter(button).slideDown('fast');
|
||||
});
|
||||
});
|
||||
} else if (close.is(':not(.hidden)')) {
|
||||
close.addClass('hidden');
|
||||
open.removeClass('hidden');
|
||||
|
||||
post.find('[component="post/replies"]').slideUp('fast', function () {
|
||||
$(this).remove();
|
||||
});
|
||||
|
||||
@@ -162,6 +162,9 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
||||
};
|
||||
|
||||
navigator.updateTextAndProgressBar = function () {
|
||||
if (!utils.isNumber(index)) {
|
||||
return;
|
||||
}
|
||||
index = index > count ? count : index;
|
||||
|
||||
$('.pagination-block .pagination-text').translateHtml('[[global:pagination.out_of, ' + index + ', ' + count + ']]');
|
||||
|
||||
@@ -122,8 +122,23 @@ SocketPosts.getReplies = function (socket, pid, callback) {
|
||||
if (!utils.isNumber(pid)) {
|
||||
return callback(new Error('[[error:invalid-data]'));
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
posts.getPidsFromSet('pid:' + pid + ':replies', 0, -1, false, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
privileges.posts.filter('read', pids, socket.uid, next);
|
||||
},
|
||||
function (pids, next) {
|
||||
posts.getPostsByPids(pids, socket.uid, next);
|
||||
}
|
||||
], function (err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
posts.getPostSummariesFromSet('pid:' + pid + ':replies', socket.uid, 0, -1, callback);
|
||||
topics.addPostData(postData, socket.uid, callback);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user