Commit 32a839e6 authored by anne.matthes's avatar anne.matthes
Browse files

Fixed OXUIB-514: Attachments deleted from draft return after saving draft

Root cause: Draft was saved before all delete requests were processed
Solution: Wait for all delete requests to be resolved, also if draft gets deleted

(cherry picked from commit 14e664df)
parent 1b68c32d
Pipeline #147184 failed with stages
in 22 minutes and 16 seconds
......@@ -56,6 +56,10 @@ define('io.ox/mail/compose/actions/extensions', [
});
};
api.waitForPendingDeleteRequests = function (baton) {
return baton.model.pendingDeletedAttachments;
};
api.removeUnusedInlineImages = function (baton) {
var inlineAttachments = baton.model.get('attachments').where({ contentDisposition: 'INLINE' }),
deferreds = _(inlineAttachments)
......
......@@ -49,6 +49,11 @@ define('io.ox/mail/compose/actions/save', [
// important: does changes in 'content' in case of pending uploads
perform: extensions.waitForPendingUploads
},
{
id: 'wait-for-pending-delete-requests',
index: 250,
perform: extensions.waitForPendingDeleteRequests
},
{
id: 'remove-unused-inline-images',
index: 300,
......
......@@ -85,6 +85,7 @@ define('io.ox/mail/compose/model', [
if (!this.prevAttributes) this.prevAttributes = data;
this.listenTo(data.attachments, 'remove', this.onRemoveAttachment);
}.bind(this));
this.pendingDeletedAttachments = $.when();
},
initialPatch: function () {
......@@ -138,7 +139,14 @@ define('io.ox/mail/compose/model', [
if (this.destroyed) return;
model.trigger('destroy');
if (model.get('id')) attachmentsAPI.remove(this.get('id'), model.get('id'));
if (model.get('id')) {
var def = attachmentsAPI.remove(this.get('id'), model.get('id'));
this.pendingDeletedAttachments = this.pendingDeletedAttachments
.catch(_.constant()).then(function () {
return def;
});
}
},
quoteMessage: (function () {
......@@ -307,7 +315,11 @@ define('io.ox/mail/compose/model', [
// that prevents any edge cases of "composition space not found"
return $.when(_(this.get('attachments')).pluck('done').map(function (def) {
return $.when(def).catch();
})).then(function () {
}))
.then(function () {
return this.pendingDeletedAttachments;
}.bind(this))
.then(function () {
return composeAPI.space.remove(this.get('id'));
}.bind(this));
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment