From 9f6102e137191f32f1f7ef2681b9a07e5463f4f5 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 25 Jun 2014 10:31:57 +1000 Subject: [PATCH] BUGFIX: double loading of replies --- .../javascripts/discourse/models/post.js | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index 05fd6d7c2d7..db73e811161 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -364,18 +364,25 @@ Discourse.Post = Discourse.Model.extend({ // Load replies to this post loadReplies: function() { + if(this.get('loadingReplies')){ + return; + } + this.set('loadingReplies', true); this.set('replies', []); - var parent = this; - return Discourse.ajax("/posts/" + (this.get('id')) + "/replies").then(function(loaded) { - var replies = parent.get('replies'); - _.each(loaded,function(reply) { - var post = Discourse.Post.create(reply); - post.set('topic', parent.get('topic')); - replies.pushObject(post); - }); - parent.set('loadingReplies', false); + var self = this; + return Discourse.ajax("/posts/" + (this.get('id')) + "/replies") + .then(function(loaded) { + var replies = self.get('replies'); + _.each(loaded,function(reply) { + var post = Discourse.Post.create(reply); + post.set('topic', self.get('topic')); + replies.pushObject(post); + }); + }) + ['finally'](function(){ + self.set('loadingReplies', false); }); },