Make the code a little prettier

This commit is contained in:
Lorenz Hübschle-Schneider 2014-02-10 19:32:00 +00:00
parent 40716ca649
commit 56055d61c8

View file

@ -376,11 +376,15 @@ function($rootScope,
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
numLines = Math.max(numLines, buffer.requestedLines * 2); numLines = Math.max(numLines, buffer.requestedLines * 2);
// Indicator that we are loading lines, hides "load more lines" link
$rootScope.loadingLines = true; $rootScope.loadingLines = true;
// Send hdata request to fetch lines for this particular buffer
ngWebsockets.send( ngWebsockets.send(
weeChat.Protocol.formatHdata({ weeChat.Protocol.formatHdata({
// "0x" is important, otherwise it won't work
path: "buffer:0x" + buffer.id + "/own_lines/last_line(-" + numLines + ")/data", path: "buffer:0x" + buffer.id + "/own_lines/last_line(-" + numLines + ")/data",
keys: [] keys: []
}) })
@ -390,6 +394,7 @@ function($rootScope,
buffer.lines.length = 0; buffer.lines.length = 0;
buffer.requestedLines = 0; buffer.requestedLines = 0;
handlers.handleLineInfo(lineinfo, false, true); handlers.handleLineInfo(lineinfo, false, true);
if (oldLength > 0) { if (oldLength > 0) {
// We're not initially loading lines into the buffer. // We're not initially loading lines into the buffer.
// Set the read marker to the beginning of the newly loaded lines // Set the read marker to the beginning of the newly loaded lines
@ -399,13 +404,13 @@ function($rootScope,
buffer.lastSeen += buffer.lines.length; buffer.lastSeen += buffer.lines.length;
} }
$rootScope.loadingLines = false; $rootScope.loadingLines = false;
// Scroll read marker to the center of the screen
$rootScope.scrollWithBuffer(true); $rootScope.scrollWithBuffer(true);
}); });
} };
return { return {
// send: send,
connect: connect, connect: connect,
disconnect: disconnect, disconnect: disconnect,
sendMessage: sendMessage, sendMessage: sendMessage,
@ -472,8 +477,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
var ab = models.getActiveBuffer(); var ab = models.getActiveBuffer();
if (ab.requestedLines < $scope.lines) { if (ab.requestedLines < $scope.lines) {
// buffer has not been loaded // buffer has not been loaded, but some lines may already be present if they arrived after we connected
// some messages may be present if they arrived after we connected
$scope.fetchMoreLines($scope.lines); $scope.fetchMoreLines($scope.lines);
} }
$rootScope.pageTitle = ab.shortName + ' | ' + ab.title; $rootScope.pageTitle = ab.shortName + ' | ' + ab.title;
@ -593,7 +597,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope.loadingLines = false; $rootScope.loadingLines = false;
$scope.fetchMoreLines = function() { $scope.fetchMoreLines = function() {
connection.fetchMoreLines($scope.lines); connection.fetchMoreLines($scope.lines);
} };
$rootScope.scrollWithBuffer = function(nonIncremental) { $rootScope.scrollWithBuffer = function(nonIncremental) {
// First, get scrolling status *before* modification // First, get scrolling status *before* modification