show toPid inline

v1.18.x
barisusakli 9 years ago
parent 6d77215f80
commit b7ce4312a9

@ -195,7 +195,21 @@ define('forum/topic', [
function addParentHandler() { function addParentHandler() {
components.get('topic').on('click', '[component="post/parent"]', function() { 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); ], 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) { SocketPosts.getPrivileges = function(socket, pids, callback) {
privileges.posts.get(pids, socket.uid, function(err, privileges) { privileges.posts.get(pids, socket.uid, function(err, privileges) {

@ -115,42 +115,36 @@ module.exports = function(Topics) {
}, },
parents: function(next) { parents: function(next) {
var parentPids = postData.map(function(postObj) { var parentPids = postData.map(function(postObj) {
return postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null return postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null;
}).filter(Boolean), }).filter(Boolean);
parentUids; var parentUids;
if (parentPids) { if (!parentPids.length) {
async.waterfall([ return next(null, []);
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) {
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);
});
},
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;
});
next(err, returnData);
});
}
], next);
} else {
next();
} }
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) {

Loading…
Cancel
Save