v1.18.x
barisusakli 10 years ago
parent a67c501eb8
commit de98df842d

@ -337,7 +337,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
var height = $(document).height(),
scrollTop = $(document).scrollTop(),
originalPostEl = $('li[data-index="0"]');
// Insert the new post
html.insertBefore(before);
@ -361,19 +361,22 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
}
function onNewPostsLoaded(html, posts) {
function getPostPrivileges(pid) {
socket.emit('posts.getPrivileges', pid, function(err, privileges) {
if(err) {
return app.alertError(err.message);
}
toggleModTools(html, privileges);
});
}
for (var x = 0, numPosts = posts.length; x < numPosts; x++) {
getPostPrivileges(posts[x].pid);
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);
}
@ -393,12 +396,14 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
showBottomPostBar();
}
function toggleModTools(postHtml, privileges) {
postHtml.find('.edit, .delete').toggleClass('none', !privileges.editable);
postHtml.find('.move').toggleClass('none', !privileges.move);
postHtml.find('.reply, .quote').toggleClass('none', !$('.post_reply').length);
var isSelfPost = parseInt(postHtml.attr('data-uid'), 10) === parseInt(app.uid, 10);
postHtml.find('.chat, .flag').toggleClass('none', isSelfPost || !app.uid);
function toggleModTools(pid, privileges) {
var postEl = $('.post-row[data-pid="' + pid + '"]');
postEl.find('.edit, .delete').toggleClass('none', !privileges.editable);
postEl.find('.move').toggleClass('none', !privileges.move);
postEl.find('.reply, .quote').toggleClass('none', !$('.post_reply').length);
var isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.uid, 10);
postEl.find('.chat, .flag').toggleClass('none', isSelfPost || !app.uid);
}
function loadMorePosts(direction) {

@ -32,11 +32,6 @@ SocketPosts.reply = function(socket, data, callback) {
return callback(err);
}
if (postData) {
postData.display_moderator_tools = false;
postData.display_move_tools = false;
}
var result = {
posts: [postData],
privileges: {
@ -248,8 +243,8 @@ SocketPosts.purge = function(socket, data, callback) {
});
};
SocketPosts.getPrivileges = function(socket, pid, callback) {
privileges.posts.get([pid], socket.uid, function(err, privileges) {
SocketPosts.getPrivileges = function(socket, pids, callback) {
privileges.posts.get(pids, socket.uid, function(err, privileges) {
if (err) {
return callback(err);
}
@ -257,8 +252,7 @@ SocketPosts.getPrivileges = function(socket, pid, callback) {
return callback(new Error('[[error:invalid-data]]'));
}
privileges[0].pid = parseInt(pid, 10);
callback(null, privileges[0]);
callback(null, privileges);
});
};

Loading…
Cancel
Save