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/initializers/title-notifications.js
Joffrey JAFFEUX 5e24436454
DEV: attempts to fix various leaks (#9428)
* DEV: attempts to fix various leaks

* scheduleOnce doesnt work with anon function

* removes the I18n change
2020-04-16 07:58:04 +02:00

34 lines
802 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");
},
teardown(container) {
container
.lookup("service:app-events")
.off("notifications:changed", this, "_updateTitle");
this.container = null;
},
_updateTitle() {
const user = this.container.lookup("current-user:main");
if (!user) return; // must be logged in
const notifications =
user.unread_notifications + user.unread_high_priority_notifications;
Discourse.updateNotificationCount(notifications);
}
};