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.
26 lines
624 B
JavaScript
26 lines
624 B
JavaScript
export default {
|
|
name: "title-notifications",
|
|
after: "message-bus",
|
|
|
|
initialize(container) {
|
|
const user = container.lookup("current-user:main");
|
|
if (!user) return; // must be logged in
|
|
|
|
this.container = container;
|
|
|
|
container
|
|
.lookup("service:app-events")
|
|
.on("notifications:changed", this, "_updateTitle");
|
|
},
|
|
|
|
_updateTitle() {
|
|
const user = this.container.lookup("current-user:main");
|
|
if (!user) return; // must be logged in
|
|
|
|
const notifications =
|
|
user.unread_notifications + user.unread_private_messages;
|
|
|
|
Discourse.updateNotificationCount(notifications);
|
|
}
|
|
};
|