From d4207ed7e0c481cf3d68f86d07e8e07dd79a08e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Thu, 20 Feb 2014 22:37:06 +0000 Subject: [PATCH] Update title with unread count Further discussion required on a few points: * show notifications only or unread lines as well? * only use this when favico is disabled, or indepently? I welcome all feedback. Fixes #22 --- js/glowingbear.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 5bd756b..345db48 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -543,6 +543,24 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', return count; }; + $rootScope.updateTitle = function() { + var unreadFragment = ''; + var notifications = $rootScope.unreadCount('notification'); + if (notifications > 0) { + // New notifications deserve an exclamation mark + unreadFragment = '(' + notifications + '!) '; + } else { + // No notifications, look for unread messages instead + var unread = $rootScope.unreadCount('unread'); + if (unread > 0) { + unreadFragment = '(' + unread + ') '; + } + } + + var activeBuffer = models.getActiveBuffer(); + $rootScope.pageTitle = unreadFragment + activeBuffer.shortName + ' | ' + activeBuffer.title; + }; + $scope.updateFavico = function() { var notifications = $rootScope.unreadCount('notification'); if (notifications > 0) { @@ -571,7 +589,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // buffer has not been loaded, but some lines may already be present if they arrived after we connected $scope.fetchMoreLines($scope.lines); } - $rootScope.pageTitle = ab.shortName + ' | ' + ab.title; + $rootScope.updateTitle(ab); // If user wants to sync hotlist with weechat // we will send a /buffer bufferName command every time @@ -591,6 +609,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.favico = new Favico({animation: 'none'}); $rootScope.$on('notificationChanged', function() { + $rootScope.updateTitle(); + if ($scope.useFavico && $scope.favico) { $scope.updateFavico(); }