Merge pull request #225 from lorenzhs/defernicklist
Defer nicklist loading until buffer is opened
This commit is contained in:
commit
a3410d45c1
2 changed files with 57 additions and 20 deletions
|
@ -275,13 +275,6 @@ function($rootScope,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
var _requestNicklist = function() {
|
|
||||||
return ngWebsockets.send(
|
|
||||||
weeChat.Protocol.formatNicklist({
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _requestBufferInfos = function() {
|
var _requestBufferInfos = function() {
|
||||||
return ngWebsockets.send(
|
return ngWebsockets.send(
|
||||||
weeChat.Protocol.formatHdata({
|
weeChat.Protocol.formatHdata({
|
||||||
|
@ -322,10 +315,6 @@ function($rootScope,
|
||||||
handlers.handleHotlistInfo(hotlist);
|
handlers.handleHotlistInfo(hotlist);
|
||||||
});
|
});
|
||||||
|
|
||||||
_requestNicklist().then(function(nicklist) {
|
|
||||||
handlers.handleNicklist(nicklist);
|
|
||||||
});
|
|
||||||
|
|
||||||
_requestSync();
|
_requestSync();
|
||||||
$log.info("Connected to relay");
|
$log.info("Connected to relay");
|
||||||
$rootScope.connected = true;
|
$rootScope.connected = true;
|
||||||
|
@ -412,6 +401,22 @@ function($rootScope,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var requestNicklist = function(bufferId, callback) {
|
||||||
|
bufferId = bufferId || null;
|
||||||
|
ngWebsockets.send(
|
||||||
|
weeChat.Protocol.formatNicklist({
|
||||||
|
buffer: bufferId
|
||||||
|
})
|
||||||
|
).then(function(nicklist) {
|
||||||
|
handlers.handleNicklist(nicklist);
|
||||||
|
if (callback !== undefined) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var fetchMoreLines = function(numLines) {
|
var fetchMoreLines = function(numLines) {
|
||||||
var buffer = models.getActiveBuffer();
|
var buffer = models.getActiveBuffer();
|
||||||
// Calculate number of lines to fetch, at least as many as the parameter
|
// Calculate number of lines to fetch, at least as many as the parameter
|
||||||
|
@ -468,7 +473,8 @@ function($rootScope,
|
||||||
disconnect: disconnect,
|
disconnect: disconnect,
|
||||||
sendMessage: sendMessage,
|
sendMessage: sendMessage,
|
||||||
sendCoreCommand: sendCoreCommand,
|
sendCoreCommand: sendCoreCommand,
|
||||||
fetchMoreLines: fetchMoreLines
|
fetchMoreLines: fetchMoreLines,
|
||||||
|
requestNicklist: requestNicklist
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
@ -640,15 +646,28 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.$on('activeBufferChanged', function() {
|
$rootScope.$on('activeBufferChanged', function() {
|
||||||
$rootScope.scrollWithBuffer(true);
|
|
||||||
|
|
||||||
var ab = models.getActiveBuffer();
|
var ab = models.getActiveBuffer();
|
||||||
|
|
||||||
if (ab.requestedLines < $scope.lines) {
|
if (ab.requestedLines < $scope.lines) {
|
||||||
// buffer has not been loaded, but some lines may already be present if they arrived after we connected
|
// buffer has not been loaded, but some lines may already be present if they arrived after we connected
|
||||||
$scope.fetchMoreLines($scope.lines);
|
$scope.fetchMoreLines($scope.lines);
|
||||||
}
|
}
|
||||||
$rootScope.updateTitle(ab);
|
$rootScope.updateTitle(ab);
|
||||||
|
|
||||||
|
// Send a request for the nicklist if it hasn't been loaded yet
|
||||||
|
if (!ab.nicklistRequested()) {
|
||||||
|
connection.requestNicklist(ab.fullName, 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
|
// If user wants to sync hotlist with weechat
|
||||||
// we will send a /buffer bufferName command every time
|
// we will send a /buffer bufferName command every time
|
||||||
// the user switches a buffer. This will ensure that notifications
|
// the user switches a buffer. This will ensure that notifications
|
||||||
|
@ -660,9 +679,6 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
// Clear search term on buffer change
|
// Clear search term on buffer change
|
||||||
$scope.search = '';
|
$scope.search = '';
|
||||||
|
|
||||||
// Check if we should show nicklist or not
|
|
||||||
$scope.showNicklist = $scope.updateShowNicklist();
|
|
||||||
|
|
||||||
if (!$rootScope.isMobileDevice()) {
|
if (!$rootScope.isMobileDevice()) {
|
||||||
$('#sendMessage').focus();
|
$('#sendMessage').focus();
|
||||||
}
|
}
|
||||||
|
@ -974,8 +990,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
if ($scope.nonicklist) {
|
if ($scope.nonicklist) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Use flat nicklist to check if empty
|
// Check if nicklist is empty
|
||||||
if (ab.flatNicklist().length === 0) {
|
if (ab.isNicklistEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
23
js/models.js
23
js/models.js
|
@ -147,6 +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 {
|
return {
|
||||||
id: pointer,
|
id: pointer,
|
||||||
fullName: fullName,
|
fullName: fullName,
|
||||||
|
@ -171,7 +190,9 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
|
||||||
history: history,
|
history: history,
|
||||||
addToHistory: addToHistory,
|
addToHistory: addToHistory,
|
||||||
getHistoryUp: getHistoryUp,
|
getHistoryUp: getHistoryUp,
|
||||||
getHistoryDown: getHistoryDown
|
getHistoryDown: getHistoryDown,
|
||||||
|
isNicklistEmpty: isNicklistEmpty,
|
||||||
|
nicklistRequested: nicklistRequested
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue