From e1102522ac0ab5297f547e83e5e4ee25215b7433 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Thu, 17 Dec 2015 16:47:41 +0100 Subject: [PATCH] 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. *