From 33119f292d25e134da746ca211cd4d002ba78858 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Tue, 30 Jul 2013 09:01:08 -0400 Subject: [PATCH] Displays buffer names screen --- js/websockets.js | 36 +++++++++++++++++++++++++++++++----- websockets.html | 3 +++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/js/websockets.js b/js/websockets.js index d47a900..8cc8861 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -125,6 +125,7 @@ weechat.factory('connection', ['$rootScope', 'colors', function($scope, colors) websocket.onopen = function (evt) { if (proto == "weechat") { doSend("init compression=off\nversion\n"); + doSend("hdata buffer:gui_buffers(*) full_name\n"); doSend("sync\n"); } else { doSend("PASS " + password + "\r\nNICK test\r\nUSER test 0 * :test\r\n"); @@ -141,7 +142,7 @@ weechat.factory('connection', ['$rootScope', 'colors', function($scope, colors) websocket.onmessage = function (evt) { protocol.setData(evt.data); message = protocol.parse() - console.log(evt); + console.log(message); $scope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ; parseMessage(message); data = evt.data; @@ -157,19 +158,44 @@ weechat.factory('connection', ['$rootScope', 'colors', function($scope, colors) } var parseMessage = function(message) { - console.log(message['id']); + if (message['id'] == '_buffer_line_added') { types[message['id']](message); } - console.log(message); + if (!message['id']) { + // should only be in case of hda objects + parseObjects(message['objects']); + } + }; + + + var parseObjects = function(objects) { + + for (var i = 0; i < objects.length ; i++) { + console.log('type', objects[i]['type']); + if (objects[i]['type'] == 'hda') { + parseHdaObject(objects[i]); + } + } } + var parseHdaObject = function(hdaObject) { + console.log('parse hda', hdaObject['content'], hdaObject['content'].length); + buffers = {}; + for (var i = 0; i < hdaObject['content'].length; i++) { + content = hdaObject['content'][i]; + console.log('content', content); + var pointer = content['pointers'][0]; + buffers[pointer] = content; + } + $scope.buffers = buffers; + } + var handleBufferLineAdded = function(message) { - var prefix = colors.parse(message['objects'][0]['content'][0]['prefix']); var message = colors.parse(message['objects'][0]['content'][0]['message']); var buffer_line = _.union(prefix, message); @@ -195,7 +221,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', 'connection', functio $rootScope.commands = [] $rootScope.buffer = [] - + $rootScope.buffers = {} $scope.hostport = "localhost:9001" $scope.proto = "weechat" $scope.password = "" diff --git a/websockets.html b/websockets.html index aa1c94c..b7866ca 100644 --- a/websockets.html +++ b/websockets.html @@ -38,6 +38,9 @@
+
+ {{ content.full_name }} +