From d60f8e32935d9b0272d636c673e4bc58908ea625 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexandre=20K=C3=BChn?= <aku@odoo.com>
Date: Tue, 15 Mar 2022 13:32:08 +0000
Subject: [PATCH] [IMP] mail: turn 'Messaging/isNotificationBlocked' into field
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Task-2793280

closes odoo/odoo#86453

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
---
 .../notification_alert/notification_alert.js  | 23 +------------------
 .../notification_alert/notification_alert.xml |  2 +-
 addons/mail/static/src/models/messaging.js    | 15 ++++++++++++
 3 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/addons/mail/static/src/components/notification_alert/notification_alert.js b/addons/mail/static/src/components/notification_alert/notification_alert.js
index 4bdc9566b8dc..06acd309a48e 100644
--- a/addons/mail/static/src/components/notification_alert/notification_alert.js
+++ b/addons/mail/static/src/components/notification_alert/notification_alert.js
@@ -4,28 +4,7 @@ import { registerMessagingComponent } from '@mail/utils/messaging_component';
 
 const { Component } = owl;
 
-export class NotificationAlert extends Component {
-
-    //--------------------------------------------------------------------------
-    // Public
-    //--------------------------------------------------------------------------
-
-    /**
-     * @returns {boolean}
-     */
-    get isNotificationBlocked() {
-        if (!this.messaging) {
-            return false;
-        }
-        const windowNotification = this.messaging.browser.Notification;
-        return (
-            windowNotification &&
-            windowNotification.permission !== "granted" &&
-            !this.messaging.isNotificationPermissionDefault
-        );
-    }
-
-}
+export class NotificationAlert extends Component {}
 
 Object.assign(NotificationAlert, {
     props: {},
diff --git a/addons/mail/static/src/components/notification_alert/notification_alert.xml b/addons/mail/static/src/components/notification_alert/notification_alert.xml
index 6ab0b1414f16..4587454b44cc 100644
--- a/addons/mail/static/src/components/notification_alert/notification_alert.xml
+++ b/addons/mail/static/src/components/notification_alert/notification_alert.xml
@@ -4,7 +4,7 @@
     <t t-name="mail.NotificationAlert" owl="1">
         <div class="o_NotificationAlert" t-attf-class="{{ className }}" t-ref="root">
             <t t-if="messaging">
-                <center t-if="isNotificationBlocked" class="o_notification_alert alert alert-primary">
+                <center t-if="messaging.isNotificationBlocked" class="o_notification_alert alert alert-primary">
                     Odoo Push notifications have been blocked. Go to your browser settings to allow them.
                 </center>
             </t>
diff --git a/addons/mail/static/src/models/messaging.js b/addons/mail/static/src/models/messaging.js
index 9d0a0dca4989..7e1f06ab6e01 100644
--- a/addons/mail/static/src/models/messaging.js
+++ b/addons/mail/static/src/models/messaging.js
@@ -176,6 +176,18 @@ registerModel({
         _computeIsCurrentUserGuest() {
             return Boolean(!this.currentPartner && this.currentGuest);
         },
+        /**
+         * @private
+         * @returns {boolean}
+         */
+        _computeIsNotificationBlocked() {
+            const windowNotification = this.browser.Notification;
+            return (
+                windowNotification &&
+                windowNotification.permission !== 'granted' &&
+                !this.isNotificationPermissionDefault
+            );
+        },
         /**
          * @private
          * @returns {EventBus}
@@ -299,6 +311,9 @@ registerModel({
         isInitialized: attr({
             default: false,
         }),
+        isNotificationBlocked: attr({
+            compute: '_computeIsNotificationBlocked',
+        }),
         /**
          * States whether browser Notification Permission is currently in its
          * 'default' state. This means it is allowed to make a request to the
-- 
GitLab