Skip to content

Commit

Permalink
DEV: Do the draft conflict check async. (#6895)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbianca authored and SamSaffron committed Jan 18, 2019
1 parent 1d0ee6f commit cf62232
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app/assets/javascripts/discourse/controllers/composer.js.es6
Expand Up @@ -835,9 +835,8 @@ export default Ember.Controller.extend({
}
}

// check if there is another draft saved on server
// or get a draft sequence number
if (!opts.draft || opts.draftSequence === undefined) {
// we need a draft sequence for the composer to work
if (opts.draftSequence === undefined) {
return Draft.get(opts.draftKey)
.then(data => {
if (opts.skipDraftCheck) {
Expand All @@ -848,17 +847,26 @@ export default Ember.Controller.extend({
return self.confirmDraftAbandon(data);
})
.then(data => {
opts.draft = opts.draft || data.draft;

// we need a draft sequence for the composer to work
if (opts.draft_sequence === undefined) {
opts.draftSequence = data.draft_sequence;
if (!opts.draft && data.draft) {
opts.draft = data.draft;
}

opts.draftSequence = data.draft_sequence;
self._setModel(composerModel, opts);
})
.then(resolve, reject);
}
// otherwise, do the draft check async
else if (!opts.draft && !opts.skipDraftCheck) {
Draft.get(opts.draftKey)
.then(data => self.confirmDraftAbandon(data))
.then(data => {
if (data.draft) {
opts.draft = data.draft;
opts.draftSequence = data.draft_sequence;
self.open(opts);
}
});
}

self._setModel(composerModel, opts);
resolve();
Expand Down

0 comments on commit cf62232

Please sign in to comment.