mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
closes #3689
This commit is contained in:
@@ -22,6 +22,12 @@ define('forum/topic/posts', [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.posts.forEach(function(post) {
|
||||||
|
post.selfPost = !!app.user.uid && parseInt(post.uid, 10) === parseInt(app.user.uid, 10);
|
||||||
|
post.display_moderator_tools = post.selfPost || ajaxify.data.isAdminOrMod;
|
||||||
|
post.display_move_tools = ajaxify.data.isAdminOrMod;
|
||||||
|
});
|
||||||
|
|
||||||
updatePostCounts(data.posts);
|
updatePostCounts(data.posts);
|
||||||
|
|
||||||
if (config.usePagination) {
|
if (config.usePagination) {
|
||||||
@@ -154,52 +160,14 @@ define('forum/topic/posts', [
|
|||||||
|
|
||||||
infinitescroll.removeExtra(components.get('post'), direction, 40);
|
infinitescroll.removeExtra(components.get('post'), direction, 40);
|
||||||
|
|
||||||
var pids = [];
|
|
||||||
for(var i=0; i<data.posts.length; ++i) {
|
|
||||||
pids.push(data.posts[i].pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
$(window).trigger('action:posts.loaded', {posts: data.posts});
|
$(window).trigger('action:posts.loaded', {posts: data.posts});
|
||||||
onNewPostsLoaded(html, pids);
|
|
||||||
|
Posts.processPage(html);
|
||||||
|
|
||||||
callback(html);
|
callback(html);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onNewPostsLoaded(html, pids) {
|
|
||||||
if (app.user.uid) {
|
|
||||||
socket.emit('posts.getPrivileges', pids, function(err, privileges) {
|
|
||||||
if(err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var i=0; i<pids.length; ++i) {
|
|
||||||
toggleModTools(pids[i], privileges[i]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
for(var i=0; i<pids.length; ++i) {
|
|
||||||
toggleModTools(pids[i], {editable: false, move: false});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Posts.processPage(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleModTools(pid, privileges) {
|
|
||||||
var postEl = components.get('post', 'pid', pid),
|
|
||||||
isSelfPost = parseInt(postEl.attr('data-uid'), 10) === parseInt(app.user.uid, 10);
|
|
||||||
|
|
||||||
if (!privileges.editable) {
|
|
||||||
postEl.find('[component="post/edit"], [component="post/delete"], [component="post/purge"]').remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!privileges.move) {
|
|
||||||
postEl.find('[component="post/move"]').remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
postEl.find('[component="user/chat"], [component="post/flag"]').toggleClass('hidden', isSelfPost || !app.user.uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
Posts.loadMorePosts = function(direction) {
|
Posts.loadMorePosts = function(direction) {
|
||||||
if (!components.get('topic').length || navigator.scrollActive) {
|
if (!components.get('topic').length || navigator.scrollActive) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ module.exports = function(privileges) {
|
|||||||
editable: editable,
|
editable: editable,
|
||||||
deletable: deletable,
|
deletable: deletable,
|
||||||
view_deleted: isAdminOrMod || results.isOwner,
|
view_deleted: isAdminOrMod || results.isOwner,
|
||||||
|
isAdminOrMod: isAdminOrMod,
|
||||||
disabled: disabled,
|
disabled: disabled,
|
||||||
tid: tid,
|
tid: tid,
|
||||||
uid: uid
|
uid: uid
|
||||||
|
|||||||
@@ -145,20 +145,6 @@ SocketPosts.getRawPost = function(socket, pid, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.getPrivileges = function(socket, pids, callback) {
|
|
||||||
privileges.posts.get(pids, socket.uid, function(err, privileges) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
if (!Array.isArray(privileges) || !privileges.length) {
|
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, privileges);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
SocketPosts.loadMoreFavourites = function(socket, data, callback) {
|
SocketPosts.loadMoreFavourites = function(socket, data, callback) {
|
||||||
loadMorePosts('uid:' + data.uid + ':favourites', socket.uid, data, callback);
|
loadMorePosts('uid:' + data.uid + ':favourites', socket.uid, data, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -283,6 +283,9 @@ module.exports = function(Topics) {
|
|||||||
topicInfo: function(next) {
|
topicInfo: function(next) {
|
||||||
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid', 'postcount'], next);
|
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid', 'postcount'], next);
|
||||||
},
|
},
|
||||||
|
parents: function(next) {
|
||||||
|
Topics.addParentPosts([postData], next);
|
||||||
|
},
|
||||||
content: function(next) {
|
content: function(next) {
|
||||||
posts.parsePost(postData, next);
|
posts.parsePost(postData, next);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,37 +114,7 @@ module.exports = function(Topics) {
|
|||||||
privileges.posts.get(pids, uid, next);
|
privileges.posts.get(pids, uid, next);
|
||||||
},
|
},
|
||||||
parents: function(next) {
|
parents: function(next) {
|
||||||
var parentPids = postData.map(function(postObj) {
|
Topics.addParentPosts(postData, next);
|
||||||
return postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;
|
|
||||||
}).filter(Boolean);
|
|
||||||
var parentUids;
|
|
||||||
|
|
||||||
if (!parentPids.length) {
|
|
||||||
return next(null, []);
|
|
||||||
}
|
|
||||||
var parentPosts;
|
|
||||||
async.waterfall([
|
|
||||||
async.apply(posts.getPostsFields, parentPids, ['pid', 'uid']),
|
|
||||||
function(_parentPosts, next) {
|
|
||||||
parentPosts = _parentPosts;
|
|
||||||
parentUids = parentPosts.map(function(postObj) { return parseInt(postObj.uid, 10); }).filter(function(uid, idx, users) {
|
|
||||||
return users.indexOf(uid) === idx;
|
|
||||||
});
|
|
||||||
|
|
||||||
user.getUsersFields(parentUids, ['username'], next);
|
|
||||||
},
|
|
||||||
function (userData, next) {
|
|
||||||
var usersMap = {};
|
|
||||||
userData.forEach(function(user) {
|
|
||||||
usersMap[user.uid] = user.username;
|
|
||||||
});
|
|
||||||
var parents = {};
|
|
||||||
parentPosts.forEach(function(post, i) {
|
|
||||||
parents[parentPids[i]] = {username: usersMap[post.uid]};
|
|
||||||
});
|
|
||||||
next(null, parents);
|
|
||||||
}
|
|
||||||
], next);
|
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -162,10 +132,9 @@ module.exports = function(Topics) {
|
|||||||
postObj.votes = postObj.votes || 0;
|
postObj.votes = postObj.votes || 0;
|
||||||
postObj.display_moderator_tools = results.privileges[i].editable;
|
postObj.display_moderator_tools = results.privileges[i].editable;
|
||||||
postObj.display_move_tools = results.privileges[i].move && postObj.index !== 0;
|
postObj.display_move_tools = results.privileges[i].move && postObj.index !== 0;
|
||||||
postObj.selfPost = parseInt(uid, 10) === parseInt(postObj.uid, 10);
|
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10);
|
||||||
postObj.parent = results.parents[parseInt(postObj.toPid, 10)];
|
|
||||||
|
|
||||||
if(postObj.deleted && !results.privileges[i].view_deleted) {
|
if (postObj.deleted && !results.privileges[i].view_deleted) {
|
||||||
postObj.content = '[[topic:post_is_deleted]]';
|
postObj.content = '[[topic:post_is_deleted]]';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,6 +149,44 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Topics.addParentPosts = function(postData, callback) {
|
||||||
|
var parentPids = postData.map(function(postObj) {
|
||||||
|
return postObj && postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;
|
||||||
|
}).filter(Boolean);
|
||||||
|
|
||||||
|
if (!parentPids.length) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
var parentPosts;
|
||||||
|
async.waterfall([
|
||||||
|
async.apply(posts.getPostsFields, parentPids, ['uid']),
|
||||||
|
function(_parentPosts, next) {
|
||||||
|
parentPosts = _parentPosts;
|
||||||
|
var parentUids = parentPosts.map(function(postObj) { return parseInt(postObj.uid, 10); }).filter(function(uid, idx, users) {
|
||||||
|
return users.indexOf(uid) === idx;
|
||||||
|
});
|
||||||
|
|
||||||
|
user.getUsersFields(parentUids, ['username'], next);
|
||||||
|
},
|
||||||
|
function (userData, next) {
|
||||||
|
var usersMap = {};
|
||||||
|
userData.forEach(function(user) {
|
||||||
|
usersMap[user.uid] = user.username;
|
||||||
|
});
|
||||||
|
var parents = {};
|
||||||
|
parentPosts.forEach(function(post, i) {
|
||||||
|
parents[parentPids[i]] = {username: usersMap[post.uid]};
|
||||||
|
});
|
||||||
|
|
||||||
|
postData.forEach(function(post) {
|
||||||
|
post.parent = parents[post.toPid];
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
Topics.calculatePostIndices = function(posts, start, stop, postCount, reverse) {
|
Topics.calculatePostIndices = function(posts, start, stop, postCount, reverse) {
|
||||||
posts.forEach(function(post, index) {
|
posts.forEach(function(post, index) {
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
|
|||||||
Reference in New Issue
Block a user