|
|
@ -699,9 +699,14 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', |
|
|
|
$rootScope.$on('activeBufferChanged', function(event, unreadSum) { |
|
|
|
$rootScope.$on('activeBufferChanged', function(event, unreadSum) { |
|
|
|
var ab = models.getActiveBuffer(); |
|
|
|
var ab = models.getActiveBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
// trim lines to 2 screenfuls + 10 lines
|
|
|
|
// Discard surplus lines. This is done *before* lines are fetched because that saves us the effort of special handling for the
|
|
|
|
ab.lines.splice(0, ab.lines.length - (2 * $scope.lines_per_screen + 10)); |
|
|
|
// case where a buffer is opened for the first time ;)
|
|
|
|
ab.requestedLines = ab.lines.length; |
|
|
|
var minRetainUnread = ab.lines.length - unreadSum + 5; // do not discard unread lines and keep 5 additional lines for context
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
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.lastSeen -= linesToRemove; // adjust readmarker
|
|
|
|
|
|
|
|
|
|
|
|
$scope.bufferlines = ab.lines; |
|
|
|
$scope.bufferlines = ab.lines; |
|
|
|
$scope.nicklist = ab.nicklist; |
|
|
|
$scope.nicklist = ab.nicklist; |
|
|
|