From fb8bcd746959f62eafcc3ca44c02c58779008317 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Thu, 14 Mar 2019 18:16:16 -0300 Subject: [PATCH] FEATURE: Enable experimental Badging API (#7173) --- .../discourse/initializers/badging.js.es6 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/assets/javascripts/discourse/initializers/badging.js.es6 diff --git a/app/assets/javascripts/discourse/initializers/badging.js.es6 b/app/assets/javascripts/discourse/initializers/badging.js.es6 new file mode 100644 index 00000000000..75672ec6b98 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/badging.js.es6 @@ -0,0 +1,19 @@ +// Updates the PWA badging if avaliable +export default { + name: "badging", + after: "message-bus", + + initialize(container) { + const appEvents = container.lookup("app-events:main"); + const user = container.lookup("current-user:main"); + + if (!user) return; // must be logged in + if (!window.ExperimentalBadge) return; // must have the Badging API + + appEvents.on("notifications:changed", () => { + let notifications = + user.get("unread_notifications") + user.get("unread_private_messages"); + window.ExperimentalBadge.set(notifications); + }); + } +};