mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55: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.loggedIn = app.user.uid ? true : false;
|
||||||
data.privileges = ajaxify.data.privileges;
|
data.privileges = ajaxify.data.privileges;
|
||||||
data.posts.forEach(function (post) {
|
Posts.modifyPostsByPrivileges(data.posts);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
updatePostCounts(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) {
|
function updatePostCounts(posts) {
|
||||||
for (var i = 0; i < posts.length; ++i) {
|
for (var i = 0; i < posts.length; ++i) {
|
||||||
var cmp = components.get('user/postcount', posts[i].uid);
|
var cmp = components.get('user/postcount', posts[i].uid);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'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 = {};
|
var Replies = {};
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ define('forum/topic/replies', ['navigator', 'components', 'translator'], functio
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onRepliesClicked(button, tid) {
|
function onRepliesClicked(button, tid) {
|
||||||
var post = button.parents('[data-pid]');
|
var post = button.closest('[data-pid]');
|
||||||
var pid = post.data('pid');
|
var pid = post.data('pid');
|
||||||
var open = button.children('[component="post/replies/open"]');
|
var open = button.children('[component="post/replies/open"]');
|
||||||
var loading = button.children('[component="post/replies/loading"]');
|
var loading = button.children('[component="post/replies/loading"]');
|
||||||
@@ -40,16 +40,20 @@ define('forum/topic/replies', ['navigator', 'components', 'translator'], functio
|
|||||||
loading.addClass('hidden');
|
loading.addClass('hidden');
|
||||||
close.removeClass('hidden');
|
close.removeClass('hidden');
|
||||||
|
|
||||||
templates.parse('partials/posts_list', data, function (html) {
|
posts.modifyPostsByPrivileges(data);
|
||||||
translator.translate(html, function (translated) {
|
var tplData ={
|
||||||
$('<div>', {component: 'post/replies'}).html(translated).hide().insertAfter(button).slideDown('fast');
|
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)')) {
|
} else if (close.is(':not(.hidden)')) {
|
||||||
close.addClass('hidden');
|
close.addClass('hidden');
|
||||||
open.removeClass('hidden');
|
open.removeClass('hidden');
|
||||||
|
|
||||||
post.find('[component="post/replies"]').slideUp('fast', function () {
|
post.find('[component="post/replies"]').slideUp('fast', function () {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -162,6 +162,9 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
};
|
};
|
||||||
|
|
||||||
navigator.updateTextAndProgressBar = function () {
|
navigator.updateTextAndProgressBar = function () {
|
||||||
|
if (!utils.isNumber(index)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
index = index > count ? count : index;
|
index = index > count ? count : index;
|
||||||
|
|
||||||
$('.pagination-block .pagination-text').translateHtml('[[global:pagination.out_of, ' + index + ', ' + count + ']]');
|
$('.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)) {
|
if (!utils.isNumber(pid)) {
|
||||||
return callback(new Error('[[error:invalid-data]'));
|
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