FIX: correctly load drafts based of id

Previously we relied on race conditions to correctly open a draft, so this
broke.

New code is deliberate.

Also corrects missing observers on composer action
This commit is contained in:
Sam Saffron
2020-04-01 14:23:26 +11:00
parent 04b431b6a4
commit b8d2261db9
3 changed files with 17 additions and 14 deletions

View File

@ -744,9 +744,12 @@ const Composer = RestModel.extend({
if (opts.postId) { if (opts.postId) {
promise = promise.then(() => promise = promise.then(() =>
this.store this.store.find("post", opts.postId).then(post => {
.find("post", opts.postId) composer.set("post", post);
.then(post => composer.setProperties({ post })) if (post) {
composer.set("topic", post.topic);
}
})
); );
} }
@ -765,7 +768,9 @@ const Composer = RestModel.extend({
this.store.find("post", opts.post.id).then(post => { this.store.find("post", opts.post.id).then(post => {
composer.setProperties({ composer.setProperties({
reply: post.raw, reply: post.raw,
originalText: post.raw originalText: post.raw,
post: post,
topic: post.topic
}); });
composer.appEvents.trigger("composer:reply-reloaded", composer); composer.appEvents.trigger("composer:reply-reloaded", composer);

View File

@ -9,6 +9,8 @@
closeComposer=closeComposer closeComposer=closeComposer
action=model.action action=model.action
tabindex=tabindex tabindex=tabindex
topic=model.topic
post=model.post
}} }}
{{/if}} {{/if}}

View File

@ -39,21 +39,17 @@ export default DropdownSelectBoxComponent.extend({
// if we change topic we want to change both snapshots // if we change topic we want to change both snapshots
if ( if (
this.get("composerModel.topic") && this.topic &&
(!_topicSnapshot || (!_topicSnapshot || this.topic.id !== _topicSnapshot.id)
this.get("composerModel.topic.id") !== _topicSnapshot.id)
) { ) {
_topicSnapshot = this.get("composerModel.topic"); _topicSnapshot = this.topic;
_postSnapshot = this.get("composerModel.post"); _postSnapshot = this.post;
this.contentChanged(); this.contentChanged();
} }
// if we hit reply on a different post we want to change postSnapshot // if we hit reply on a different post we want to change postSnapshot
if ( if (this.post && (!_postSnapshot || this.post.id !== _postSnapshot.id)) {
this.get("composerModel.post") && _postSnapshot = this.post;
(!_postSnapshot || this.get("composerModel.post.id") !== _postSnapshot.id)
) {
_postSnapshot = this.get("composerModel.post");
this.contentChanged(); this.contentChanged();
} }