Fix an issue with notifications being shown when fetching old lines

@xt, does this fix the issue for you?

While we're at it, fix the annoying jump-to-bottom when loading more lines.
This commit is contained in:
Lorenz Hübschle-Schneider 2014-02-21 16:33:10 +00:00
parent f10e44efe4
commit 4736da2d92

View file

@ -44,7 +44,7 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
models.closeBuffer(buffer); models.closeBuffer(buffer);
}; };
var handleLine = function(line, initial, loadingMoreLines) { var handleLine = function(line, manually) {
var message = new models.BufferLine(line); var message = new models.BufferLine(line);
var buffer = models.getBuffer(message.buffer); var buffer = models.getBuffer(message.buffer);
buffer.requestedLines++; buffer.requestedLines++;
@ -53,15 +53,15 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
message = plugins.PluginManager.contentForMessage(message, $rootScope.visible); message = plugins.PluginManager.contentForMessage(message, $rootScope.visible);
buffer.addLine(message); buffer.addLine(message);
if (initial) { if (manually) {
buffer.lastSeen++; buffer.lastSeen++;
} }
if (buffer.active && !initial && !loadingMoreLines) { if (buffer.active && !manually) {
$rootScope.scrollWithBuffer(); $rootScope.scrollWithBuffer();
} }
if (!initial && !buffer.active) { if (!manually && !buffer.active) {
if (buffer.notify > 1 && _.contains(message.tags, 'notify_message') && !_.contains(message.tags, 'notify_none')) { if (buffer.notify > 1 && _.contains(message.tags, 'notify_message') && !_.contains(message.tags, 'notify_none')) {
buffer.unread++; buffer.unread++;
$rootScope.$emit('notificationChanged'); $rootScope.$emit('notificationChanged');
@ -111,13 +111,13 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
* *
* (lineinfo) messages are specified by this client. It is request after bufinfo completes * (lineinfo) messages are specified by this client. It is request after bufinfo completes
*/ */
var handleLineInfo = function(message, initial, loadingMoreLines) { var handleLineInfo = function(message, manually) {
var lines = message.objects[0].content.reverse(); var lines = message.objects[0].content.reverse();
if (initial === undefined) { if (manually === undefined) {
initial = true; manually = true;
} }
lines.forEach(function(l) { lines.forEach(function(l) {
handleLine(l, initial, loadingMoreLines); handleLine(l, manually);
}); });
}; };
@ -451,12 +451,21 @@ function($rootScope,
).then(function(lineinfo) { ).then(function(lineinfo) {
// delete old lines and add new ones // delete old lines and add new ones
var oldLength = buffer.lines.length; var oldLength = buffer.lines.length;
var setReadmarker = (buffer.lastSeen >= 0);
buffer.lines.length = 0; buffer.lines.length = 0;
buffer.requestedLines = 0; buffer.requestedLines = 0;
handlers.handleLineInfo(lineinfo, false, true); handlers.handleLineInfo(lineinfo, true);
// Advance read marker by number of newly loaded lines if (setReadmarker) {
buffer.lastSeen += buffer.lines.length - oldLength; // Read marker was somewhere in the old lines - we don't need it any more,
// set it to the boundary between old and new. This way, we stay at the exact
// same position in the text through the scrollWithBuffer below
buffer.lastSeen = buffer.lines.length - oldLength - 1;
} else {
// We are currently fetching at least some unread lines, so we need to keep
// the read marker position correct
buffer.lastSeen -= oldLength;
}
$rootScope.loadingLines = false; $rootScope.loadingLines = false;
// Scroll read marker to the center of the screen // Scroll read marker to the center of the screen