From 730c7dab8d4fb452e7860aba56ca3e15feb563ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 8 Mar 2014 21:26:15 +0000 Subject: [PATCH] Load lines before nicklist Nicklist is not nearly as important as the actual lines, load them first for better perceived performance. Parsing the nicklist can take a noticeable amount of time for channels with thousands of occupants. This also improves/fixes the nicklist emptiness check --- js/glowingbear.js | 23 +++++++++++++---------- js/models.js | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 97aabfc..b8975ff 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -649,19 +649,25 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $rootScope.$on('activeBufferChanged', function() { var ab = models.getActiveBuffer(); - if (ab.isNicklistEmpty()) { - var bufferId = '0x' + ab.id; // WeeChat needs the 0x prefix - connection.requestNicklist(bufferId, function() { - $scope.showNicklist = $scope.updateShowNicklist(); - }); - } - if (ab.requestedLines < $scope.lines) { // buffer has not been loaded, but some lines may already be present if they arrived after we connected $scope.fetchMoreLines($scope.lines); } $rootScope.updateTitle(ab); + // Send a request for the nicklist if it hasn't been loaded yet + if (!ab.nicklistRequested()) { + var bufferId = '0x' + ab.id; // WeeChat needs the 0x prefix + connection.requestNicklist(bufferId, function() { + $scope.showNicklist = $scope.updateShowNicklist(); + // Scroll after nicklist has been loaded, as it may break long lines + $rootScope.scrollWithBuffer(true); + }); + } else { + // Check if we should show nicklist or not + $scope.showNicklist = $scope.updateShowNicklist(); + } + $rootScope.scrollWithBuffer(true); // If user wants to sync hotlist with weechat @@ -675,9 +681,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Clear search term on buffer change $scope.search = ''; - // Check if we should show nicklist or not - $scope.showNicklist = $scope.updateShowNicklist(); - if (!$rootScope.isMobileDevice()) { $('#sendMessage').focus(); } diff --git a/js/models.js b/js/models.js index db330bd..67e8345 100644 --- a/js/models.js +++ b/js/models.js @@ -147,13 +147,25 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) } }; + + // Check if the nicklist is empty, i.e., no nicks present + // This checks for the presence of people, not whether a + // request for the nicklist has been made var isNicklistEmpty = function() { for (var obj in nicklist) { - return false; + if (obj !== 'root') { + return false; + } } return true; }; + var nicklistRequested = function() { + // If the nicklist has been requested but is empty, it + // still has a 'root' property. Check for its existence. + return nicklist.hasOwnProperty('root'); + }; + return { id: pointer, fullName: fullName, @@ -179,7 +191,8 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) addToHistory: addToHistory, getHistoryUp: getHistoryUp, getHistoryDown: getHistoryDown, - isNicklistEmpty: isNicklistEmpty + isNicklistEmpty: isNicklistEmpty, + nicklistRequested: nicklistRequested }; };