From e1102522ac0ab5297f547e83e5e4ee25215b7433 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Thu, 17 Dec 2015 16:47:41 +0100 Subject: [PATCH 1/2] weechat.js: implement infolist --- js/weechat.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/js/weechat.js b/js/weechat.js index 4a6d4f0..640ccbd 100644 --- a/js/weechat.js +++ b/js/weechat.js @@ -23,9 +23,7 @@ 'buf': this._getString, 'arr': this._getArray, 'htb': this._getHashTable, - 'inl': function() { - this._warnUnimplemented('infolist'); - } + 'inl': this._getInfolist, }; // string value for some object types @@ -699,6 +697,37 @@ return WeeChatProtocol._formatCmd(params.id, 'info', parts); }; + /** + * Formats an infolist command. + * + * @param params Parameters: + * id: command ID (optional) + * name: infolist name (mandatory) + * pointer: optional + * arguments: optional + * @return Formatted infolist command string + */ + WeeChatProtocol.formatInfolist = function(params) { + var defaultParams = { + id: null, + pointer: null, + args: null + + }; + var parts = []; + + params = WeeChatProtocol._mergeParams(defaultParams, params); + parts.push(params.name); + if (params.pointer !== null) { + parts.push(params.pointer); + } + if (params.pointer !== null) { + parts.push(params.args); + } + + return WeeChatProtocol._formatCmd(params.id, 'infolist', parts); + }; + /** * Formats a nicklist command. * @@ -1143,6 +1172,35 @@ return values; }, + /** + * Reads an infolist object from the current set of data + * + * @return Array + */ + _getInfolist: function() { + var self = this; + var name; + var count; + var values; + + name = this._getString(); + count = this._getInt(); + values = []; + + for (var i = 0; i < count; i++) { + var itemcount = self._getInt(); + var litem = []; + for (var j = 0; j < itemcount; j++) { + var item = {}; + item[self._getString()] = self._runType(self._getType()); + litem.push(item); + } + values.push(litem); + } + + return values; + }, + /** * Reads a specified number of bytes from current set data. * From c9dbdc39e432867ddfb22626c6c955fd822a3d3a Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Thu, 17 Dec 2015 17:45:34 +0100 Subject: [PATCH 2/2] fetch weechat configuration variables Usage: fetchConfValue('weechat.look.buffer_time_format') will result in models.wconfig['weechat.look.buffer_time_format'] to be set when the result returns from WeeChat. Could maybe be extended to also call a callback when it's available if needed. --- js/connection.js | 13 ++++++++++++- js/handlers.js | 22 ++++++++++++++++++++++ js/models.js | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/js/connection.js b/js/connection.js index a876ee6..319219f 100644 --- a/js/connection.js +++ b/js/connection.js @@ -99,7 +99,7 @@ weechat.factory('connection', $log.info("Connected to relay"); $rootScope.connected = true; }, - function(e) { + function() { handleWrongPassword(); } ); @@ -306,6 +306,17 @@ weechat.factory('connection', }); }; + var fetchConfValue = function(name) { + ngWebsockets.send( + weeChat.Protocol.formatInfolist({ + name: "option", + pointer: 0, + args: name + }) + ).then(function(i) { + handlers.handleConfValue(i); + }); + }; var fetchMoreLines = function(numLines) { $log.debug('Fetching ', numLines, ' lines'); diff --git a/js/handlers.js b/js/handlers.js index 1a75b5d..5de02d1 100644 --- a/js/handlers.js +++ b/js/handlers.js @@ -13,6 +13,27 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific models.version = version.split(".").map(function(c) { return parseInt(c); }); }; + var handleConfValue = function(message) { + var infolist = message.objects[0].content; + for (var i = 0; i < infolist.length ; i++) { + var key, val; + var item = infolist[i]; + for (var j = 0; j < item.length ; j++) { + var confitem = item[j]; + if (confitem.full_name) { + key = confitem.full_name; + } + if (confitem.value) { + val = confitem.value; + } + } + if (key && val) { + $log.debug('Setting wconfig "' + key + '" to value "' + val + '"'); + models.wconfig[key] = val; + } + } + }; + var handleBufferClosing = function(message) { var bufferMessage = message.objects[0].content[0]; var bufferId = bufferMessage.pointers[0]; @@ -392,6 +413,7 @@ weechat.factory('handlers', ['$rootScope', '$log', 'models', 'plugins', 'notific return { handleVersionInfo: handleVersionInfo, + handleConfValue: handleConfValue, handleEvent: handleEvent, handleLineInfo: handleLineInfo, handleHotlistInfo: handleHotlistInfo, diff --git a/js/models.js b/js/models.js index 4bb239e..f6d7f63 100644 --- a/js/models.js +++ b/js/models.js @@ -11,6 +11,9 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) // WeeChat version this.version = null; + // WeeChat configuration values + this.wconfig = {}; + // Save outgoing queries this.outgoingQueries = [];