This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/initializers/badging.js
Roman Rizzi 7a2e8d3ead
DEV: Add the missing app subdirectory (#9499)
* DEV: Add missing  directory to the Discourse ember app

* DEV: Resolve imports correctly
2020-04-23 10:07:54 -03:00

24 lines
586 B
JavaScript

// Updates the PWA badging if avaliable
export default {
name: "badging",
after: "message-bus",
initialize(container) {
if (!navigator.setAppBadge) return; // must have the Badging API
const user = container.lookup("current-user:main");
if (!user) return; // must be logged in
this.notifications =
user.unread_notifications + user.unread_high_priority_notifications;
container
.lookup("service:app-events")
.on("notifications:changed", this, "_updateBadge");
},
_updateBadge() {
navigator.setAppBadge(this.notifications);
}
};