Robin Ward f5d391a48a
REFACTOR: Move app-events:main to service:app-events ()
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.
2019-10-04 10:06:08 -04:00

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);
}
};