Maintainers
+Maintainers
This module is maintained by the OCA.
diff --git a/web_notify/static/src/js/services/notification.esm.js b/web_notify/static/src/js/services/notification.esm.js
index 7f8c28136..eebc3c126 100644
--- a/web_notify/static/src/js/services/notification.esm.js
+++ b/web_notify/static/src/js/services/notification.esm.js
@@ -1,4 +1,3 @@
-/** @odoo-module */
import {Notification} from "@web/core/notifications/notification";
import {patch} from "@web/core/utils/patch";
diff --git a/web_notify/static/src/js/services/notification_services.esm.js b/web_notify/static/src/js/services/notification_services.esm.js
index c37cc174f..1ac2f71d6 100644
--- a/web_notify/static/src/js/services/notification_services.esm.js
+++ b/web_notify/static/src/js/services/notification_services.esm.js
@@ -1,64 +1,48 @@
-/** @odoo-module **/
-
import {markup} from "@odoo/owl";
-import {browser} from "@web/core/browser/browser";
import {registry} from "@web/core/registry";
export const webNotificationService = {
dependencies: ["bus_service", "notification", "action"],
- start(env, {bus_service, notification, action}) {
- let webNotifTimeouts = {};
- /**
- * Displays the web notification on user's screen
- * @param {*} notifications
- */
- function displaywebNotification(notifications) {
- Object.values(webNotifTimeouts).forEach((notif) =>
- browser.clearTimeout(notif)
+ start(env, {bus_service, notification: notificationService, action}) {
+ function displayWebNotification(notification) {
+ let buttons = [];
+ if (notification.action) {
+ const params = notification.action.context?.params || {};
+
+ buttons = [
+ {
+ name: params.button_name || env._t("Open"),
+ primary: true,
+ onClick: async () => {
+ await action.doAction(notification.action);
+ },
+ ...(params.button_icon && {icon: params.button_icon}),
+ },
+ ];
+ }
+
+ const notificationRemove = notificationService.add(
+ markup(notification.message),
+ {
+ title: notification.title,
+ type: notification.type,
+ sticky: notification.sticky,
+ className: notification.className,
+ buttons: buttons.map((button) => {
+ const onClick = button.onClick;
+ button.onClick = async () => {
+ await onClick();
+ notificationRemove();
+ };
+ return button;
+ }),
+ }
);
- webNotifTimeouts = {};
- notifications.forEach((notif) => {
- browser.setTimeout(() => {
- var buttons = [];
- if (notif.action) {
- const params =
- (notif.action.context && notif.action.context.params) || {};
- buttons = [
- {
- name: params.button_name || env._t("Open"),
- primary: true,
- onClick: async () => {
- await action.doAction(notif.action);
- },
- ...(params.button_icon && {icon: params.button_icon}),
- },
- ];
- }
- const notificationRemove = notification.add(markup(notif.message), {
- title: notif.title,
- type: notif.type,
- sticky: notif.sticky,
- className: notif.className,
- buttons: buttons.map((button) => {
- const onClick = button.onClick;
- button.onClick = async () => {
- await onClick();
- notificationRemove();
- };
- return button;
- }),
- });
- });
- });
}
- bus_service.addEventListener("notification", ({detail: notifications}) => {
- for (const {payload, type} of notifications) {
- if (type === "web.notify") {
- displaywebNotification(payload);
- }
- }
+ bus_service.subscribe("web_notify", (payload) => {
+ displayWebNotification(payload);
});
bus_service.start();
},
diff --git a/web_notify/tests/test_res_users.py b/web_notify/tests/test_res_users.py
index 6cae1b256..16f065966 100644
--- a/web_notify/tests/test_res_users.py
+++ b/web_notify/tests/test_res_users.py
@@ -26,7 +26,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": SUCCESS})
- payload = json.loads(news.message)["payload"][0]
+ payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload)
def test_notify_danger(self):
@@ -45,7 +45,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": DANGER})
- payload = json.loads(news.message)["payload"][0]
+ payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload)
def test_notify_warning(self):
@@ -64,7 +64,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": WARNING})
- payload = json.loads(news.message)["payload"][0]
+ payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload)
def test_notify_info(self):
@@ -83,7 +83,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": INFO})
- payload = json.loads(news.message)["payload"][0]
+ payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload)
def test_notify_default(self):
@@ -102,7 +102,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news))
test_msg.update({"type": DEFAULT})
- payload = json.loads(news.message)["payload"][0]
+ payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload)
def test_notify_many(self):