From 8a885bb5baf0eab4e9ebd48c52d3d14abddb87c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 15 Jun 2023 10:46:38 +0000 Subject: [PATCH] [FIX] mail: play sound effect from new message with push notif MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When odoo tab is out-of-focus and user receives a new message, it should play a sound effect. This works when showing notification in Odoo, but when push notifications were enabled it did not play the audio. This commit fixes the issue by playing audio when receiving push notification of new message while out-of-focusing the tab. closes odoo/odoo#125305 X-original-commit: b0b4f300705595df31588e747e1b12ad99f6d8d0 Signed-off-by: Sébastien Theys (seb) Signed-off-by: Alexandre Kühn (aku) --- .../src/core/common/out_of_focus_service.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/addons/mail/static/src/core/common/out_of_focus_service.js b/addons/mail/static/src/core/common/out_of_focus_service.js index 873d924e96a..8b324a90547 100644 --- a/addons/mail/static/src/core/common/out_of_focus_service.js +++ b/addons/mail/static/src/core/common/out_of_focus_service.js @@ -103,14 +103,7 @@ export class OutOfFocusService { */ async sendOdooNotification(message, options) { this.notificationService.add(message, options); - if (this.canPlayAudio && this.multiTab.isOnMainTab()) { - try { - await this.audio.play(); - } catch { - // Ignore errors due to the user not having interracted - // with the page before playing the sound. - } - } + this._playSound(); } /** @@ -131,6 +124,18 @@ export class OutOfFocusService { window.focus(); notification.close(); }); + this._playSound(); + } + + async _playSound() { + if (this.canPlayAudio && this.multiTab.isOnMainTab()) { + try { + await this.audio.play(); + } catch { + // Ignore errors due to the user not having interracted + // with the page before playing the sound. + } + } } get canPlayAudio() {