From a098464af3dcf60fa461071fc33a176203ef8227 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 1 Apr 2020 16:40:55 +1100 Subject: [PATCH] FIX: ninja edit for replies not working There is an edge case, in some cases when pulling a post from the store there is no topic, this ensures it is loaded correctly. --- .../javascripts/discourse/models/composer.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 1b1fd0ace3a..0f6d9ae620c 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -769,11 +769,23 @@ const Composer = RestModel.extend({ composer.setProperties({ reply: post.raw, originalText: post.raw, - post: post, - topic: post.topic + post: post }); - composer.appEvents.trigger("composer:reply-reloaded", composer); + promise = Promise.resolve(); + // edge case ... make a post then edit right away + // store does not have topic for the post + if (composer.topic && composer.topic.id === post.topic_id) { + // nothing to do ... we have the right topic + } else { + promise = this.store.find("topic", post.topic_id).then(topic => { + this.set("topic", topic); + }); + } + + return promise.then(() => { + composer.appEvents.trigger("composer:reply-reloaded", composer); + }); }) ); } else if (opts.action === REPLY && opts.quote) {