Fix the initial loading of lines

This fixes a bug where the initial line loading would be triggered multiple times,
and a bug that incorrectly set requestedLines, causing this behaviour to repeat
This commit is contained in:
Lorenz Hübschle-Schneider 2014-07-06 11:30:38 +01:00
parent a904add7cc
commit 1194b170e5

View file

@ -483,6 +483,9 @@ function($rootScope,
// Don't do that if we didn't get any more lines than we already had // Don't do that if we didn't get any more lines than we already had
var setReadmarker = (buffer.lastSeen >= 0) && (oldLength !== buffer.lines.length); var setReadmarker = (buffer.lastSeen >= 0) && (oldLength !== buffer.lines.length);
buffer.lines.length = 0; buffer.lines.length = 0;
// We need to set the number of requested lines to 0 here, because parsing a line
// increments it. This is needed to also count newly arriving lines while we're
// already connected.
buffer.requestedLines = 0; buffer.requestedLines = 0;
// Count number of lines recieved // Count number of lines recieved
var linesReceivedCount = lineinfo.objects[0].content.length; var linesReceivedCount = lineinfo.objects[0].content.length;
@ -702,7 +705,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
var surplusLines = ab.lines.length - (2 * $scope.lines_per_screen + 10); // retain up to 2*(screenful + 10) + 10 lines because magic numbers var surplusLines = ab.lines.length - (2 * $scope.lines_per_screen + 10); // retain up to 2*(screenful + 10) + 10 lines because magic numbers
var linesToRemove = Math.max(0, Math.min(minRetainUnread, surplusLines)); var linesToRemove = Math.max(0, Math.min(minRetainUnread, surplusLines));
ab.lines.splice(0, linesToRemove); // remove the lines from the buffer ab.lines.splice(0, linesToRemove); // remove the lines from the buffer
ab.requestedLines = ab.lines.length; // to ensure that the correct amount of lines is fetched should more be requested ab.requestedLines -= linesToRemove; // to ensure that the correct amount of lines is fetched should more be requested
ab.lastSeen -= linesToRemove; // adjust readmarker ab.lastSeen -= linesToRemove; // adjust readmarker
$scope.bufferlines = ab.lines; $scope.bufferlines = ab.lines;
@ -723,8 +726,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
if (ab.requestedLines < $scope.lines_per_screen) { if (ab.requestedLines < $scope.lines_per_screen) {
// 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
// try to determine how many lines to fetch // try to determine how many lines to fetch
var numLines = $scope.lines_per_screen; // that's a screenful plus 10 lines var numLines = $scope.lines_per_screen + 10; // that's (a screenful plus 10 lines) plus 10 lines, just to be safe
unreadSum += 10; // let's just add a 10 line safety margin here again
if (unreadSum > numLines) { if (unreadSum > numLines) {
// request up to 4*(screenful + 10 lines) // request up to 4*(screenful + 10 lines)
numLines = Math.min(4*numLines, unreadSum); numLines = Math.min(4*numLines, unreadSum);