diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 4832b06b5d8..0533d47eed1 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -253,10 +253,29 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, // Toggle the star on the topic - toggleStar: function(e) { + toggleStar: function() { this.get('content').toggleStar(); }, + /** + Toggle the replies this post is a reply to + + @method showReplyHistory + **/ + toggleReplyHistory: function(post) { + var replyHistory = post.get('replyHistory'), + topicController = this; + + if (replyHistory.length > 0) { + replyHistory.clear(); + } else { + post.set('loadingReplyHistory', true); + topicController.get('postStream').findReplyHistory(post).then(function () { + post.set('loadingReplyHistory', false); + }); + } + }, + /** Clears the pin from a topic for the currently logged in user diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index 420a11acdee..bec021326eb 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -8,6 +8,10 @@ **/ Discourse.Post = Discourse.Model.extend({ + init: function() { + this.set('replyHistory', []); + }, + shareUrl: function() { var user = Discourse.User.current(); var userSuffix = user ? '?u=' + user.get('username_lower') : ''; @@ -383,12 +387,6 @@ Discourse.Post.reopenClass({ }); }, - loadByPostNumber: function(topicId, postId) { - return Discourse.ajax("/posts/by_number/" + topicId + "/" + postId + ".json").then(function (result) { - return Discourse.Post.create(result); - }); - }, - loadQuote: function(postId) { return Discourse.ajax("/posts/" + postId + ".json").then(function(result) { var post = Discourse.Post.create(result); diff --git a/app/assets/javascripts/discourse/models/post_stream.js b/app/assets/javascripts/discourse/models/post_stream.js index bc251c6e683..c8c6636fd9f 100644 --- a/app/assets/javascripts/discourse/models/post_stream.js +++ b/app/assets/javascripts/discourse/models/post_stream.js @@ -459,6 +459,26 @@ Discourse.PostStream = Em.Object.extend({ } }, + /** + Returns the "thread" of posts in the history of a post. + + @method findReplyHistory + @param {Discourse.Post} post the post whose history we want + @returns {Array} the posts in the history. + **/ + findReplyHistory: function(post) { + var postStream = this, + url = "/posts/" + post.get('id') + "/reply-history.json"; + + return Discourse.ajax(url).then(function(result) { + return result.map(function (p) { + return postStream.storePost(Discourse.Post.create(p)); + }); + }).then(function (replyHistory) { + post.set('replyHistory', replyHistory); + }); + }, + /** Returns the closest post number given a postNumber that may not exist in the stream. For example, if the user asks for a post that's deleted or otherwise outside the range. diff --git a/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars b/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars index 0b1d9a70f09..a5d0be4e201 100644 --- a/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars @@ -10,9 +10,9 @@
- {{#if view.previousPost}}{{/if}} + {{#if view.parentView.previousPost}}{{/if}}
{{{unbound cooked}}} - {{#unless view.previousPost}}{{/unless}} + {{#unless view.parentView.previousPost}}{{/unless}}
diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index c5a490d7baa..efb2f3a08ca 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -1,16 +1,12 @@
- + {{view Discourse.ReplyHistory contentBinding="replyHistory"}}
{{#if showUserReplyTab}} - - {{#if loadingParent}} + + {{#if loadingReplyHistory}} {{i18n loading}} {{else}} {{i18n post.in_reply_to}} @@ -31,7 +27,7 @@
-
+
{{#unless controller.multiSelect}}