diff --git a/addons/mail/static/src/components/notification_request/notification_request.js b/addons/mail/static/src/components/notification_request/notification_request.js index c9cdc9cb60f..5863430d9d9 100644 --- a/addons/mail/static/src/components/notification_request/notification_request.js +++ b/addons/mail/static/src/components/notification_request/notification_request.js @@ -6,10 +6,6 @@ const { Component } = owl; export class NotificationRequest extends Component { - //-------------------------------------------------------------------------- - // Public - //-------------------------------------------------------------------------- - /** * @returns {NotificationRequestView} */ @@ -17,45 +13,6 @@ export class NotificationRequest extends Component { return this.props.record; } - //-------------------------------------------------------------------------- - // Private - //-------------------------------------------------------------------------- - - /** - * Handle the response of the user when prompted whether push notifications - * are granted or denied. - * - * @private - * @param {string} value - */ - _handleResponseNotificationPermission(value) { - this.messaging.refreshIsNotificationPermissionDefault(); - if (value !== 'granted') { - this.messaging.userNotificationManager.sendNotification({ - message: this.env._t("Odoo will not have the permission to send native notifications on this device."), - title: this.env._t("Permission denied"), - }); - } - } - - //-------------------------------------------------------------------------- - // Handlers - //-------------------------------------------------------------------------- - - /** - * @private - */ - _onClick() { - const windowNotification = this.messaging.browser.Notification; - const def = windowNotification && windowNotification.requestPermission(); - if (def) { - def.then(this._handleResponseNotificationPermission.bind(this)); - } - if (!this.messaging.device.isSmall) { - this.messaging.messagingMenu.close(); - } - } - } Object.assign(NotificationRequest, { diff --git a/addons/mail/static/src/components/notification_request/notification_request.xml b/addons/mail/static/src/components/notification_request/notification_request.xml index 49d1708e086..4633ec6ce76 100644 --- a/addons/mail/static/src/components/notification_request/notification_request.xml +++ b/addons/mail/static/src/components/notification_request/notification_request.xml @@ -3,7 +3,7 @@ -
+
Avatar of OdooBot diff --git a/addons/mail/static/src/models/messaging.js b/addons/mail/static/src/models/messaging.js index f42d4e08c11..9424097d303 100644 --- a/addons/mail/static/src/models/messaging.js +++ b/addons/mail/static/src/models/messaging.js @@ -58,6 +58,21 @@ registerPatch({ return partner.getChat(); } }, + /** + * Handles the response of the user when prompted whether push + * notifications are granted or denied. + * + * @param {string} value + */ + handleResponseNotificationPermission(value) { + this.refreshIsNotificationPermissionDefault(); + if (value !== 'granted') { + this.userNotificationManager.sendNotification({ + message: this.env._t("Odoo will not have the permission to send native notifications on this device."), + title: this.env._t("Permission denied"), + }); + } + }, /** * Display a notification to the user. * @@ -200,6 +215,13 @@ registerPatch({ isNotificationPermissionDefault: Boolean(browserNotification) && browserNotification.permission === 'default', }); }, + requestNotificationPermission() { + const windowNotification = this.messaging.browser.Notification; + const def = windowNotification && windowNotification.requestPermission(); + if (def) { + def.then((permission) => this.messaging.handleResponseNotificationPermission(permission)); + } + }, /** * Starts messaging and related records. * diff --git a/addons/mail/static/src/models/notification_request_view.js b/addons/mail/static/src/models/notification_request_view.js index 38be3d76fa5..1a03530681b 100644 --- a/addons/mail/static/src/models/notification_request_view.js +++ b/addons/mail/static/src/models/notification_request_view.js @@ -8,6 +8,14 @@ import { sprintf } from '@web/core/utils/strings'; registerModel({ name: 'NotificationRequestView', + recordMethods: { + onClick() { + this.messaging.requestNotificationPermission(); + if (!this.messaging.device.isSmall) { + this.messaging.messagingMenu.close(); + } + }, + }, fields: { headerText: attr({ compute() {