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
This commit is contained in:
Lorenz Hübschle-Schneider 2014-03-08 21:26:15 +00:00
parent ac548777fc
commit 730c7dab8d
2 changed files with 28 additions and 12 deletions

View file

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

View file

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