FEATURE: Display notification count in title for logged in users (#7184)

This replaces the 'contextual' counters for logged in users. We will still use the old method for anon users
This commit is contained in:
David Taylor
2019-03-18 12:59:47 +00:00
committed by GitHub
parent 0c01cb2cf3
commit 4e8c174ee5
6 changed files with 114 additions and 16 deletions

View File

@ -41,7 +41,7 @@ const Discourse = Ember.Application.extend({
Resolver: buildResolver("discourse"),
@observes("_docTitle", "hasFocus", "notifyCount")
@observes("_docTitle", "hasFocus", "contextCount", "notificationCount")
_titleChanged() {
let title = this.get("_docTitle") || Discourse.SiteSettings.title;
@ -51,15 +51,18 @@ const Discourse = Ember.Application.extend({
$("title").text(title);
}
const notifyCount = this.get("notifyCount");
if (notifyCount > 0 && !Discourse.User.currentProp("dynamic_favicon")) {
title = `(${notifyCount}) ${title}`;
var displayCount = Discourse.User.current()
? this.get("notificationCount")
: this.get("contextCount");
if (displayCount > 0 && !Discourse.User.currentProp("dynamic_favicon")) {
title = `(${displayCount}) ${title}`;
}
document.title = title;
},
@observes("notifyCount")
@observes("contextCount", "notificationCount")
faviconChanged() {
if (Discourse.User.currentProp("dynamic_favicon")) {
let url = Discourse.SiteSettings.site_favicon_url;
@ -71,7 +74,11 @@ const Discourse = Ember.Application.extend({
url = Discourse.getURL("/favicon/proxied?" + encodeURIComponent(url));
}
new window.Favcount(url).set(this.get("notifyCount"));
var displayCount = Discourse.User.current()
? this.get("notificationCount")
: this.get("contextCount");
new window.Favcount(url).set(displayCount);
}
},
@ -83,23 +90,33 @@ const Discourse = Ember.Application.extend({
});
},
notifyTitle(count) {
this.set("notifyCount", count);
updateContextCount(count) {
this.set("contextCount", count);
},
notifyBackgroundCountIncrement() {
updateNotificationCount(count) {
if (!this.get("hasFocus")) {
this.set("notificationCount", count);
}
},
incrementBackgroundContextCount() {
if (!this.get("hasFocus")) {
this.set("backgroundNotify", true);
this.set("notifyCount", (this.get("notifyCount") || 0) + 1);
this.set("contextCount", (this.get("contextCount") || 0) + 1);
}
},
@observes("hasFocus")
resetBackgroundNotifyCount() {
resetCounts() {
if (this.get("hasFocus") && this.get("backgroundNotify")) {
this.set("notifyCount", 0);
this.set("contextCount", 0);
}
this.set("backgroundNotify", false);
if (this.get("hasFocus")) {
this.set("notificationCount", 0);
}
},
authenticationComplete(options) {