mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
show toPid inline
This commit is contained in:
@@ -195,7 +195,21 @@ define('forum/topic', [
|
||||
|
||||
function addParentHandler() {
|
||||
components.get('topic').on('click', '[component="post/parent"]', function() {
|
||||
navigator.scrollToPost(parseInt(this.getAttribute('data-index'), 10), true);
|
||||
var toPid = $(this).attr('data-topid');
|
||||
var content = $(this).parents('[component="post"]').find('[component="post/parent/content"]');
|
||||
if (!content.hasClass('hidden')) {
|
||||
return content.addClass('hidden');
|
||||
} else if (content.html().length) {
|
||||
return content.removeClass('hidden');
|
||||
}
|
||||
|
||||
socket.emit('posts.getPost', toPid, function(err, post) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
content.html(post.content).removeClass('hidden');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +145,29 @@ SocketPosts.getRawPost = function(socket, pid, callback) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
SocketPosts.getPost = function(socket, pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
privileges.posts.can('read', pid, socket.uid, next);
|
||||
},
|
||||
function(canRead, next) {
|
||||
if (!canRead) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
posts.getPostsByPids([pid], socket.uid, next);
|
||||
},
|
||||
function(postData, next) {
|
||||
if (!postData.length) {
|
||||
return next(new Error('[[error:no-post]]'));
|
||||
}
|
||||
postData = postData[0];
|
||||
if (parseInt(postData.deleted, 10) === 1) {
|
||||
return next(new Error('[[error:no-post]]'));
|
||||
}
|
||||
next(null, postData);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
SocketPosts.getPrivileges = function(socket, pids, callback) {
|
||||
privileges.posts.get(pids, socket.uid, function(err, privileges) {
|
||||
|
||||
@@ -115,42 +115,36 @@ module.exports = function(Topics) {
|
||||
},
|
||||
parents: function(next) {
|
||||
var parentPids = postData.map(function(postObj) {
|
||||
return postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null
|
||||
}).filter(Boolean),
|
||||
parentUids;
|
||||
return postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;
|
||||
}).filter(Boolean);
|
||||
var parentUids;
|
||||
|
||||
if (parentPids) {
|
||||
if (!parentPids.length) {
|
||||
return next(null, []);
|
||||
}
|
||||
var parentPosts;
|
||||
async.waterfall([
|
||||
async.apply(posts.getPostsFields, parentPids, ['pid', 'tid', 'uid']),
|
||||
function(postsArr, next) {
|
||||
// To use Posts.getUserInfoForPosts would be overkill here...
|
||||
parentUids = postsArr.map(function(postObj) { return parseInt(postObj.uid, 10); }).filter(function(uid, idx, users) {
|
||||
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'], function(err, userDataArr) {
|
||||
var userData = {};
|
||||
userDataArr.forEach(function(user) {
|
||||
userData[user.uid] = user;
|
||||
});
|
||||
next(err, postsArr, userData);
|
||||
});
|
||||
user.getUsersFields(parentUids, ['username'], next);
|
||||
},
|
||||
function(postsArr, userData, next) {
|
||||
var returnData = {};
|
||||
posts.getPostIndices(postsArr, uid, function(err, indices) {
|
||||
postsArr.forEach(function(post, idx) {
|
||||
var pid = parseInt(post.pid, 10);
|
||||
returnData[pid] = _.clone(userData[parseInt(post.uid, 10)]);
|
||||
returnData[pid].index = indices[idx]+0;
|
||||
function (userData, next) {
|
||||
var usersMap = {};
|
||||
userData.forEach(function(user) {
|
||||
usersMap[user.uid] = user.username;
|
||||
});
|
||||
next(err, returnData);
|
||||
var parents = {};
|
||||
parentPosts.forEach(function(post, i) {
|
||||
parents[parentPids[i]] = {username: usersMap[post.uid]};
|
||||
});
|
||||
next(null, parents);
|
||||
}
|
||||
], next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user