From 5c7ac96f2a357686a99f7ed59e4a38522f50964a Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Fri, 16 Sep 2011 23:31:57 +0100 Subject: [PATCH] better /list --- js/front.js | 82 +++++++++++++++++++++++++++++++++++++++-------------- node/app.js | 24 ++++++++++++++-- 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/js/front.js b/js/front.js index 619125d..e0c107f 100644 --- a/js/front.js +++ b/js/front.js @@ -12,6 +12,8 @@ kiwi.front = { buffer: [], buffer_pos: 0, + cache: {}, + original_topic: '', init: function () { @@ -616,30 +618,68 @@ kiwi.front = { }, 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 = $(''); - body = table.children('tbody:first'); - chanList = _.sortBy(chanList, function (channel) { - return parseInt(channel.num_users, 10); - }).reverse(); - for (chan in chanList) { - body.append($('')); - } 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: ''}; + } + 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.'); }, @@ -1271,7 +1311,7 @@ kiwi.front = { }; fg = col(p1); bg = col(p3); - return '' + p4 + ''; + return '' + p4 + ''; }); return msg; } diff --git a/node/app.js b/node/app.js index 03e6a54..6243647 100644 --- a/node/app.js +++ b/node/app.js @@ -181,10 +181,18 @@ this.parseIRCMessage = function (websocket, ircSocket, data) { 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; @@ -199,13 +207,23 @@ this.parseIRCMessage = function (websocket, ircSocket, data) { 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; @@ -642,7 +660,7 @@ this.websocketListen = function (port, host, handler, secure, key, cert) { 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) { -- 2.25.1
Channel NameMembersTopic
' + chanList[chan].channel + '' + chanList[chan].num_users + '' + kiwi.front.format(chanList[chan].topic) + '
' + data[chans].channel + '' + data[chans].num_users + '' + kiwi.front.format(data[chans].topic) + '