diff --git a/index.html b/index.html index 4605e00..a7d0234 100644 --- a/index.html +++ b/index.html @@ -282,6 +282,12 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
diff --git a/js/glowingbear.js b/js/glowingbear.js index 4d4af04..62c9a0d 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -24,9 +24,10 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc var handleLine = function(line, initial) { var message = new models.BufferLine(line); + var buffer = models.getBuffer(message.buffer); + buffer.requestedLines++; // Only react to line if its displayed if (message.displayed) { - var buffer = models.getBuffer(message.buffer); message = plugins.PluginManager.contentForMessage(message, $rootScope.visible); buffer.addLine(message); @@ -88,10 +89,11 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc * * (lineinfo) messages are specified by this client. It is request after bufinfo completes */ - var handleLineInfo = function(message) { + var handleLineInfo = function(message, initial) { var lines = message.objects[0].content.reverse(); + if (initial === undefined) initial = true; lines.forEach(function(l) { - handleLine(l, true); + handleLine(l, initial); }); }; @@ -381,13 +383,37 @@ function($rootScope, })); }; + var getMoreLines = function(numLines) { + var buffer = models.getActiveBuffer(); + if (numLines === undefined) { + var numLines = Math.max(40, buffer.requestedLines * 2); + } + + $rootScope.loadingLines = true; + ngWebsockets.send( + weeChat.Protocol.formatHdata({ + path: "buffer:0x" + buffer.id + "/own_lines/last_line(-" + numLines + ")/data", + keys: [] + }) + ).then(function(lineinfo) { + // delete old lines and add new ones + var oldLength = buffer.lines.length; + buffer.lines.length = 0; + buffer.requestedLines = 0; + handlers.handleLineInfo(lineinfo, false); + buffer.lastSeen = buffer.lines.length - oldLength - 1; + $rootScope.loadingLines = false; + }); + } + return { // send: send, connect: connect, disconnect: disconnect, sendMessage: sendMessage, - sendCoreCommand: sendCoreCommand + sendCoreCommand: sendCoreCommand, + getMoreLines: getMoreLines }; }]); @@ -562,6 +588,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } }; + $rootScope.loadingLines = false; + $scope.fetchMoreLines = function(numLines) { + connection.getMoreLines(numLines); + } + $rootScope.scrollWithBuffer = function(nonIncremental) { // First, get scrolling status *before* modification // This is required to determine where we were in the buffer pre-change diff --git a/js/models.js b/js/models.js index 655fd6d..8c3cb38 100644 --- a/js/models.js +++ b/js/models.js @@ -18,6 +18,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) var local_variables = message.local_vars; var notify = 3; // Default 3 == message var lines = []; + var requestedLines = 0; var nicklist = {}; var flatnicklist = []; var history = []; @@ -153,6 +154,7 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) number: number, title: title, lines: lines, + requestedLines: requestedLines, addLine: addLine, lastSeen: lastSeen, unread: unread, |