diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 30b90e545..e01b376f3 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -1821,7 +1821,8 @@ const MessageTray = new Lang.Class({ summaryItem: new SummaryItem(source), notifyId: 0, destroyId: 0, - mutedChangedId: 0 + mutedChangedId: 0, + countChangedId: 0, }; let summaryItem = obj.summaryItem; @@ -1846,6 +1847,9 @@ const MessageTray = new Lang.Class({ return source != notification.source; }); })); + obj.countChangedId = source.connect('count-updated', Lang.bind(this, function() { + this.emit('indicator-count-updated'); + })); summaryItem.actor.connect('clicked', Lang.bind(this, function(actor, button) { @@ -1865,6 +1869,7 @@ const MessageTray = new Lang.Class({ Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() { this._updateState(); return false; })); this.emit('source-added', source); + this.emit('indicator-count-updated'); this._updateNoMessagesLabel(); }, @@ -1883,10 +1888,12 @@ const MessageTray = new Lang.Class({ source.disconnect(obj.notifyId); source.disconnect(obj.destroyId); source.disconnect(obj.mutedChangedId); + source.disconnect(obj.countChangedId); summaryItem.destroy(); this.emit('source-removed', source); + this.emit('indicator-count-updated'); this._updateNoMessagesLabel(); }, @@ -1911,6 +1918,23 @@ const MessageTray = new Lang.Class({ this._removeSource(source); }, + get hasChatSources() { + for (let source of this._sources.keys()) + if (source.isChat) + return true; + return false; + }, + + get indicatorCount() { + if (!this._sources.size) + return 0; + + let count = 0; + for (let source of this._sources.keys()) + count += source.indicatorCount; + return count; + }, + _onNotificationDestroy: function(notification) { if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) { this._updateNotificationTimeout(0); diff --git a/js/ui/overviewControls.js b/js/ui/overviewControls.js index b396ff012..823ae90c6 100644 --- a/js/ui/overviewControls.js +++ b/js/ui/overviewControls.js @@ -451,45 +451,21 @@ const MessagesIndicator = new Lang.Class({ this.actor.add_actor(this._container); this.actor.add_actor(this._highlight); - Main.messageTray.connect('source-added', Lang.bind(this, this._onSourceAdded)); - Main.messageTray.connect('source-removed', Lang.bind(this, this._onSourceRemoved)); - - let sources = Main.messageTray.getSources(); - sources.forEach(Lang.bind(this, function(source) { this._onSourceAdded(null, source); })); + Main.messageTray.connect('indicator-count-updated', Lang.bind(this, this._sync)); + this._sync(); this._viewSelector.connect('page-changed', Lang.bind(this, this._updateVisibility)); Main.overview.connect('showing', Lang.bind(this, this._updateVisibility)); }, - _onSourceAdded: function(tray, source) { - if (source.trayIcon) - return; - - source.connect('count-updated', Lang.bind(this, this._updateCount)); - this._sources.push(source); - this._updateCount(); - }, - - _onSourceRemoved: function(tray, source) { - this._sources.splice(this._sources.indexOf(source), 1); - this._updateCount(); - }, - - _updateCount: function() { - let count = 0; - let hasChats = false; - this._sources.forEach(Lang.bind(this, - function(source) { - count += source.indicatorCount; - hasChats |= source.isChat; - })); - + _sync: function() { + let count = Main.messageTray.indicatorCount; this._count = count; this._label.text = ngettext("%d new message", "%d new messages", count).format(count); - this._icon.visible = hasChats; + this._icon.visible = Main.messageTray.hasChatSources; this._updateVisibility(); },