From 9ac7b341ec68fa358b28df0d44c5bf38aa8a56b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Thu, 20 Feb 2014 22:35:34 +0000 Subject: [PATCH 1/4] Make use of favico an option @tribut: does this resolve your issue? --- index.html | 10 +++++++ js/glowingbear.js | 71 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index 62fc52e..fbbecdd 100644 --- a/index.html +++ b/index.html @@ -255,6 +255,16 @@ $ openssl req -nodes -newkey rsa:4096 -keyout relay.pem -x509 -days 365 -out rel +
  • +
    +
    + +
    +
    +
  • diff --git a/js/glowingbear.js b/js/glowingbear.js index 2160e04..5bd756b 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -527,6 +527,42 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.isinstalled = false; } + // Reduce buffers with "+" operation over a key. Mostly useful for unread/notification counts. + $rootScope.unreadCount = function(type) { + if (!type) { + type = "unread"; + } + + // Do this the old-fashioned way with iterating over the keys, as underscore proved to be error-prone + var keys = Object.keys(models.model.buffers); + var count = 0; + for (var key in keys) { + count += models.model.buffers[keys[key]][type]; + } + + return count; + }; + + $scope.updateFavico = function() { + var notifications = $rootScope.unreadCount('notification'); + if (notifications > 0) { + $scope.favico.badge(notifications, { + bgColor: '#d00', + textColor: '#fff' + }); + } else { + var unread = $rootScope.unreadCount('unread'); + if (unread === 0) { + $scope.favico.reset(); + } else { + $scope.favico.badge(unread, { + bgColor: '#5CB85C', + textColor: '#ff0' + }); + } + } + }; + $rootScope.$on('activeBufferChanged', function() { $rootScope.scrollWithBuffer(true); @@ -555,25 +591,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.favico = new Favico({animation: 'none'}); $rootScope.$on('notificationChanged', function() { - var notifications = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.notification;}); - if (typeof notifications !== 'number') { - return; - } - if (notifications > 0) { - $scope.favico.badge(notifications, { - bgColor: '#d00', - textColor: '#fff' - }); - } else { - var unread = _.reduce(models.model.buffers, function(memo, num) { return (parseInt(memo)||0) + num.unread;}); - if (unread === 0) { - $scope.favico.reset(); - } else { - $scope.favico.badge(unread, { - bgColor: '#5CB85C', - textColor: '#ff0' - }); - } + if ($scope.useFavico && $scope.favico) { + $scope.updateFavico(); } }); @@ -609,6 +628,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $store.bind($scope, "noembed", false); // Save setting for channel ordering $store.bind($scope, "orderbyserver", false); + // Save setting for updating favicon + $store.bind($scope, "useFavico", true); // Save setting for displaying embeds in rootScope so it can be used from service $rootScope.visible = $scope.noembed === false; @@ -652,6 +673,18 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number'; }); + $scope.$watch('useFavico', function() { + // this check is necessary as this is called on page load, too + if (!$rootScope.connected) { + return; + } + if ($scope.useFavico) { + $scope.updateFavico(); + } else { + $scope.favico.reset(); + } + }); + $rootScope.predicate = $scope.orderbyserver ? 'serverSortKey' : 'number'; $scope.setActiveBuffer = function(bufferId, key) { 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 2/4] 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(); } From df1bb08749809efd59b21ff83e7227501ff725d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Fri, 21 Feb 2014 10:22:27 +0000 Subject: [PATCH 3/4] Only update title for notifications, not other kinds of activity Also make the unread count the first thing in the title --- index.html | 2 +- js/glowingbear.js | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index fbbecdd..ba8434d 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ - + diff --git a/js/glowingbear.js b/js/glowingbear.js index 345db48..0c5ca58 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -548,17 +548,13 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', var notifications = $rootScope.unreadCount('notification'); if (notifications > 0) { // New notifications deserve an exclamation mark - unreadFragment = '(' + notifications + '!) '; + $rootScope.notificationStatus = '(' + notifications + ') '; } else { - // No notifications, look for unread messages instead - var unread = $rootScope.unreadCount('unread'); - if (unread > 0) { - unreadFragment = '(' + unread + ') '; - } + $rootScope.notificationStatus = ''; } var activeBuffer = models.getActiveBuffer(); - $rootScope.pageTitle = unreadFragment + activeBuffer.shortName + ' | ' + activeBuffer.title; + $rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.title; }; $scope.updateFavico = function() { From fb9d5af5fc16fac2f8613d5fbfafe27d8720688e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Fri, 21 Feb 2014 10:50:29 +0000 Subject: [PATCH 4/4] localstorage: Correctly check whether value is set before setting default The old condition always overwrote boolean values that were set to false with the default m( Check for undefined instead. --- js/localstorage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/localstorage.js b/js/localstorage.js index 971ac1d..cfcf1ce 100644 --- a/js/localstorage.js +++ b/js/localstorage.js @@ -98,7 +98,7 @@ ls.factory("$store",function($parse){ */ bind: function ($scope, key, def) { def = def || ''; - if (!publicMethods.get(key)) { + if (publicMethods.get(key) === undefined) { publicMethods.set(key, def); } $parse(key).assign($scope, publicMethods.get(key));