weechat.js: implement infolist

This commit is contained in:
Tor Hveem 2015-12-17 16:47:41 +01:00
parent aeb0cdf70e
commit e1102522ac

View file

@ -23,9 +23,7 @@
'buf': this._getString, 'buf': this._getString,
'arr': this._getArray, 'arr': this._getArray,
'htb': this._getHashTable, 'htb': this._getHashTable,
'inl': function() { 'inl': this._getInfolist,
this._warnUnimplemented('infolist');
}
}; };
// string value for some object types // string value for some object types
@ -699,6 +697,37 @@
return WeeChatProtocol._formatCmd(params.id, 'info', parts); 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. * Formats a nicklist command.
* *
@ -1143,6 +1172,35 @@
return values; 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. * Reads a specified number of bytes from current set data.
* *