mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 12:15:38 +08:00

AppEvents was always a service object in disguise, so we should move it to the correct place in the application. Doing this allows other service objects to inject it easily without container access. In the future we should also deprecate `this.appEvents` without an explicit injection too.
24 lines
585 B
JavaScript
24 lines
585 B
JavaScript
// Updates the PWA badging if avaliable
|
|
export default {
|
|
name: "badging",
|
|
after: "message-bus",
|
|
|
|
initialize(container) {
|
|
if (!window.ExperimentalBadge) 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_private_messages;
|
|
|
|
container
|
|
.lookup("service:app-events")
|
|
.on("notifications:changed", this, "_updateBadge");
|
|
},
|
|
|
|
_updateBadge() {
|
|
window.ExperimentalBadge.set(this.notifications);
|
|
}
|
|
};
|