Skip to content

Node.js based forum software built for the modern web

Added support for a theme to generate a link back to a parent post

Julian Lam09d23c3dd033
diff --git a/public/src/client/topic.js b/public/src/client/topic.js
index 2ea69a9dfd..18402c1f58 100644
--- a/public/src/client/topic.js
+++ b/public/src/client/topic.js
@@ -57,6 +57,8 @@ define('forum/topic', [
addBlockQuoteHandler();
+ addParentHandler();
+
handleBookmark(tid);
handleKeys();
@@ -191,6 +193,11 @@ define('forum/topic', [
});
}
+ function addParentHandler() {
+ components.get('topic').on('click', '[component="post/parent"]', function() {
+ navigator.scrollToPost(parseInt(this.getAttribute('data-index'), 10), true);
+ });
+ }
function enableInfiniteLoadingOrPagination() {
if (!config.usePagination) {
diff --git a/src/topics/posts.js b/src/topics/posts.js
index bf1e51ac4d..573c8b6ca8 100644
--- a/src/topics/posts.js
+++ b/src/topics/posts.js
@@ -112,6 +112,45 @@ module.exports = function(Topics) {
},
privileges: function(next) {
privileges.posts.get(pids, uid, next);
+ },
+ parents: function(next) {
+ var parentPids = postData.map(function(postObj) {
+ return postObj.hasOwnProperty('toPid') ? parseInt(postObj.toPid, 10) : null
+ }).filter(Boolean),
+ parentUids;
+
+ if (parentPids) {
+ 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) {
+ return users.indexOf(uid) === idx;
+ });
+
+ user.getMultipleUserFields(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();
+ }
}
}, function(err, results) {
if (err) {
@@ -130,6 +169,7 @@ module.exports = function(Topics) {
postObj.display_moderator_tools = results.privileges[i].editable;
postObj.display_move_tools = results.privileges[i].move && postObj.index !== 0;
postObj.selfPost = parseInt(uid, 10) === parseInt(postObj.uid, 10);
+ postObj.parent = results.parents[parseInt(postObj.toPid, 10)];
if(postObj.deleted && !results.privileges[i].view_deleted) {
postObj.content = '[[topic:post_is_deleted]]';