diff --git a/addons/mail/static/src/models/attachment.js b/addons/mail/static/src/models/attachment.js index 9e0282f51cb..5c6491df899 100644 --- a/addons/mail/static/src/models/attachment.js +++ b/addons/mail/static/src/models/attachment.js @@ -92,6 +92,7 @@ registerModel({ if (!this.exists()) { return; } + this.messaging.messagingBus.trigger('o-attachment-deleted', { attachment: this }); this.delete(); }, /** diff --git a/addons/mail/static/src/models/file_uploader.js b/addons/mail/static/src/models/file_uploader.js index d3c422edb7a..504e05e3d58 100644 --- a/addons/mail/static/src/models/file_uploader.js +++ b/addons/mail/static/src/models/file_uploader.js @@ -37,6 +37,9 @@ registerModel({ */ async uploadFiles(files) { await this._performUpload({ files }); + if (!this.exists()) { + return; + } if (this.fileInput && this.fileInput.el) { this.fileInput.el.value = ''; } diff --git a/addons/mail/static/src/models/messaging_notification_handler.js b/addons/mail/static/src/models/messaging_notification_handler.js index a6f3e14d4ae..ba29cc7fc19 100644 --- a/addons/mail/static/src/models/messaging_notification_handler.js +++ b/addons/mail/static/src/models/messaging_notification_handler.js @@ -148,6 +148,7 @@ registerModel({ _handleNotificationAttachmentDelete(payload) { const attachment = this.messaging.models['Attachment'].findFromIdentifyingData(payload); if (attachment) { + this.messaging.messagingBus.trigger('o-attachment-deleted', { attachment }); attachment.delete(); } }, diff --git a/addons/mail/static/tests/helpers/mock_server.js b/addons/mail/static/tests/helpers/mock_server.js index d603e97aa3b..4e758195002 100644 --- a/addons/mail/static/tests/helpers/mock_server.js +++ b/addons/mail/static/tests/helpers/mock_server.js @@ -352,6 +352,7 @@ patch(MockServer.prototype, 'mail', { * @param {integer} attachment_id */ async _mockRouteMailAttachmentRemove(attachment_id) { + this.pyEnv['bus.bus']._sendone(this.currentPartnerId, 'ir.attachment/delete', { id: attachment_id }); return this.pyEnv['ir.attachment'].unlink([attachment_id]); }, diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js index 72372de850d..4918706344f 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_tests.js @@ -1292,7 +1292,7 @@ QUnit.test('remove an attachment from composer does not need any confirmation', const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create({}); - const { click, messaging, openDiscuss } = await start({ + const { afterEvent, messaging, openDiscuss } = await start({ discuss: { context: { active_id: mailChannelId1 }, }, @@ -1317,7 +1317,18 @@ QUnit.test('remove an attachment from composer does not need any confirmation', "should have only one attachment" ); - await click('.o_AttachmentCard_asideItemUnlink'); + const attachmentLocalId = document.querySelector('.o_AttachmentCard').dataset.id; + await afterNextRender(() => afterEvent({ + eventName: 'o-attachment-deleted', + func() { + document.querySelector('.o_AttachmentCard_asideItemUnlink').click(); + }, + message: "should wait until attachment is deleted", + predicate: ({ attachment }) => { + return attachment.localId === attachmentLocalId; + }, + })); + assert.containsNone( document.body, '.o_Composer .o_AttachmentCard',