[IMP] mail: move code from components to models (NotificationRequest)

Move methods on component to model record methods.

Task-3004192.

closes odoo/odoo#101952

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Louis Wicket (wil)
2022-10-06 00:36:48 +02:00
parent 2cfa76e0c3
commit 5768b03bdc
4 changed files with 31 additions and 44 deletions
@@ -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, {
@@ -3,7 +3,7 @@
<t t-name="mail.NotificationRequest" owl="1">
<t t-if="notificationRequestView">
<div class="o_NotificationListItem o_NotificationRequest d-flex flex-shrink-0 align-items-center p-1 cursor-pointer" t-attf-class="{{ className }}" t-on-click="_onClick" t-ref="root">
<div class="o_NotificationListItem o_NotificationRequest d-flex flex-shrink-0 align-items-center p-1 cursor-pointer" t-attf-class="{{ className }}" t-on-click="notificationRequestView.onClick" t-ref="root">
<div class="o_NotificationListItem_sidebar o_NotificationRequest_sidebar m-1">
<div class="o_NotificationListItem_imageContainer o_NotificationRequest_imageContainer o_NotificationRequest_sidebarItem position-relative">
<img class="o_NotificationListItem_image o_NotificationRequest_image w-100 h-100 rounded-circle" t-att-src="messaging.partnerRoot.avatarUrl" alt="Avatar of OdooBot"/>
@@ -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.
*
@@ -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() {