Try to fetch all unread lines if that is a reasonable amount

Partially fixes #139 in that it tries to accomplish this, but until we can request
only non-filtered lines from WeeChat, the best thing we can do is guessing.
This commit is contained in:
Lorenz Hübschle-Schneider 2014-03-07 17:07:05 +00:00
parent a3410d45c1
commit 203680ff58
2 changed files with 18 additions and 5 deletions

View file

@ -645,12 +645,20 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
}
};
$rootScope.$on('activeBufferChanged', function() {
$rootScope.$on('activeBufferChanged', function(event, unreadSum) {
var ab = models.getActiveBuffer();
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);
// try to determine how many lines to fetch
var numLines = $scope.lines; // that's a screenful plus 10 lines
unreadSum += 10; // let's just add a 10 line safety margin here again
if (unreadSum > numLines) {
// request up to 4*(screenful + 10 lines)
numLines = Math.min(4*numLines, unreadSum);
}
$scope.fetchMoreLines(numLines);
}
$rootScope.updateTitle(ab);
@ -847,8 +855,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
$rootScope.loadingLines = false;
$scope.fetchMoreLines = function() {
connection.fetchMoreLines($scope.lines);
$scope.fetchMoreLines = function(numLines) {
if (!numLines) {
numLines = $scope.lines;
}
connection.fetchMoreLines(numLines);
};
$rootScope.scrollWithBuffer = function(nonIncremental) {

View file

@ -419,11 +419,13 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
previousBuffer.lastSeen = previousBuffer.lines.length-1;
}
var unreadSum = activeBuffer.unread + activeBuffer.notification;
activeBuffer.active = true;
activeBuffer.unread = 0;
activeBuffer.notification = 0;
$rootScope.$emit('activeBufferChanged');
$rootScope.$emit('activeBufferChanged', unreadSum);
$rootScope.$emit('notificationChanged');
return true;
};