buffer: [],
buffer_pos: 0,
+ cache: {},
+
original_topic: '',
init: function () {
},
onChannelListStart: function (e, data) {
- kiwi.data.set('chanList', []);
- },
- onChannelList: function (e, data) {
- var network_name = kiwi.gateway.network_name,
- chanList = kiwi.data.get('chanList');
- chanList.push(data);
- kiwi.data.set('chanList', chanList);
- },
- onChannelListEnd: function (e, data) {
- var chanList, tab, table, body, chan;
+ var tab, table;
+ console.log('/list start');
+ console.profile('list');
- chanList = kiwi.data.get('chanList');
tab = new Utilityview('Channel List');
+ tab.div.css('overflow-y', 'scroll');
table = $('<table><thead style="font-weight: bold;"><tr><td>Channel Name</td><td>Members</td><td style="padding-left: 2em;">Topic</td></tr></thead><tbody style="vertical-align: top;"></tbody>');
- body = table.children('tbody:first');
- chanList = _.sortBy(chanList, function (channel) {
- return parseInt(channel.num_users, 10);
- }).reverse();
- for (chan in chanList) {
- body.append($('<tr><td><a class="chan">' + chanList[chan].channel + '</a></td><td style="text-align: center;">' + chanList[chan].num_users + '</td><td style="padding-left: 2em;">' + kiwi.front.format(chanList[chan].topic) + '</td></tr>'));
- }
tab.div.append(table);
- tab.div.css('overflow-y', 'scroll');
- tab.show();
+
+ kiwi.front.cache.list = {chans: [], tab: tab, table: table,
+ update: function (newChans) {
+ var body = this.table.children('tbody:first').detach(),
+ chan,
+ html;
+
+ html = '';
+ for (chan in newChans) {
+ this.chans.push(newChans[chan]);
+ html += newChans[chan].html;
+ }
+ body.append(html);
+ this.table.append(body);
+
+ },
+ finalise: function () {
+ var body = this.table.children('tbody:first').detach(),
+ list,
+ chan;
+
+ list = $.makeArray($(body).children());
+
+ for (chan in list) {
+ list[chan] = $(list[chan]).detach();
+ }
+
+ list = _.sortBy(list, function (channel) {
+ return parseInt(channel.children('.num_users').first().text(), 10);
+ }).reverse();
+
+ for (chan in list) {
+ body.append(list[chan]);
+ }
+
+ this.table.append(body);
+
+ }};
+ },
+ onChannelList: function (e, data) {
+ var chans;
+ console.log(data);
+ data = data.chans;
+ //data = [data];
+ for (chans in data) {
+ data[chans] = {data: data[chans], html: '<tr><td><a class="chan">' + data[chans].channel + '</a></td><td class="num_users" style="text-align: center;">' + data[chans].num_users + '</td><td style="padding-left: 2em;">' + kiwi.front.format(data[chans].topic) + '</td></tr>'};
+ }
+ kiwi.front.cache.list.update(data);
+ },
+ onChannelListEnd: function (e, data) {
+ kiwi.front.cache.list.finalise();
+ kiwi.front.cache.list.tab.show();
+ console.profileEnd();
+ console.log('/list end.');
},
};
fg = col(p1);
bg = col(p3);
- return '<span style="' + ((fg !== null) ? 'color: ' + fg +'; ' : '') + ((bg !== null) ? 'background-color: ' + bg + ';' : '') + '">' + p4 + '</span>';
+ return '<span style="' + ((fg !== null) ? 'color: ' + fg + '; ' : '') + ((bg !== null) ? 'background-color: ' + bg + ';' : '') + '">' + p4 + '</span>';
});
return msg;
}
case ircNumerics.RPL_LISTSTART:
(function () {
websocket.sendClientEvent('list_start', {server: ''});
+ websocket.kiwi.buffer.list = [];
}());
break;
case ircNumerics.RPL_LISTEND:
(function () {
+ if (websocket.kiwi.buffer.list.length > 0) {
+ websocket.kiwi.buffer.list = _.sortBy(websocket.kiwi.buffer.list, function (channel) {
+ return channel.num_users;
+ });
+ websocket.sendClientEvent('list_channel', {chans: websocket.kiwi.buffer.list});
+ websocket.kiwi.buffer.list = [];
+ }
websocket.sendClientEvent('list_end', {server: ''});
}());
break;
modes = msg.trailing.split(' ', 1);
topic = msg.trailing.substring(msg.trailing.indexOf(' ') + 1);
- websocket.sendClientEvent('list_channel', {
+ //websocket.sendClientEvent('list_channel', {
+ websocket.kiwi.buffer.list.push({
server: '',
channel: channel,
topic: topic,
modes: modes,
- num_users: num_users
+ num_users: parseInt(num_users, 10)
});
+
+ if (websocket.kiwi.buffer.list.length > 200) {
+ websocket.kiwi.buffer.list = _.sortBy(websocket.kiwi.buffer.list, function (channel) {
+ return channel.num_users;
+ });
+ websocket.sendClientEvent('list_channel', {chans: websocket.kiwi.buffer.list});
+ websocket.kiwi.buffer.list = [];
+ }
+
}());
break;
this.websocketConnection = function (websocket) {
var con;
- websocket.kiwi = {address: websocket.handshake.address.address};
+ websocket.kiwi = {address: websocket.handshake.address.address, buffer: {list: []}};
con = kiwi.connections[websocket.kiwi.address];
if (con.count >= kiwi.config.max_client_conns) {