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
This commit is contained in:
Lorenz Hübschle-Schneider 2014-02-20 22:37:06 +00:00
parent 9ac7b341ec
commit d4207ed7e0

View file

@ -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();
}