diff --git a/index.html b/index.html index d5abc5d..415c94a 100644 --- a/index.html +++ b/index.html @@ -48,7 +48,7 @@
- {{ content.full_name }} + {{ content.fullName }}
{{ bufferline.date | date: 'H:mm:ss'}} diff --git a/js/models.js b/js/models.js index d746e84..32699bc 100644 --- a/js/models.js +++ b/js/models.js @@ -2,6 +2,20 @@ var models = angular.module('weechatModels', []); models.factory('models', ['colors', function(colors) { + function Buffer(message) { + + var fullName = message['full_name'] + var pointer = message['pointers'][0] + var lines = [] + + return { + id: pointer, + fullName: fullName, + lines: lines, + } + + } + function BufferLine(weechatBufferLine) { /* @@ -40,7 +54,8 @@ models.factory('models', ['colors', function(colors) { } return { - BufferLine: BufferLine + BufferLine: BufferLine, + Buffer: Buffer } diff --git a/js/websockets.js b/js/websockets.js index 25cec1c..45993ca 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -194,8 +194,9 @@ weechat.factory('imagePlugin', [function() { weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', function($rootScope, colors, models, pluginManager) { var handleBufferClosing = function(message) { - var buffer_pointer = message['objects'][0]['content'][0]['pointers'][0]; - $rootScope.closeBuffer(buffer_pointer); + var bufferMessage = message['objects'][0]['content'][0]; + var buffer = new models.Buffer(bufferMessage); + $rootScope.closeBuffer(buffer.id); } var handleBufferLineAdded = function(message) { @@ -223,9 +224,9 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', } var handleBufferOpened = function(message) { - var fullName = message['objects'][0]['content'][0]['full_name'] - var buffer = message['objects'][0]['content'][0]['pointers'][0] - $rootScope.buffers[buffer] = { 'id': buffer, 'lines':[], 'full_name':fullName } + var bufferMessage = message['objects'][0]['content'][0]; + var buffer = new models.Buffer(bufferMessage); + $rootScope.buffers[buffer.id] = buffer; } @@ -241,14 +242,11 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', // buffers objects var buffers = {}; for (var i = 0; i < bufferInfos.length ; i++) { - var bufferInfo = bufferInfos[i]; - var pointer = bufferInfo['pointers'][0]; - bufferInfo['id'] = pointer; - bufferInfo['lines'] = []; - buffers[pointer] = bufferInfo + var buffer = new models.Buffer(bufferInfos[i]); + buffers[buffer.id] = buffer; if (i == 0) { // first buffer is active buffer by default - $rootScope.activeBuffer = buffers[pointer]; + $rootScope.activeBuffer = buffers[buffer.id]; } } $rootScope.buffers = buffers; @@ -350,7 +348,7 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct var sendMessage = function(message) { doSend(WeeChatProtocol.formatInput({ - buffer: $rootScope.activeBuffer['full_name'], + buffer: $rootScope.activeBuffer['fullName'], data: message })); }