mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
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:
@ -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) {
|
||||
|
Reference in New Issue
Block a user