From bb6a9775ae45e2b2470f4638a76fb557c2f71c1d Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Sat, 17 Mar 2012 07:11:24 +0000 Subject: [PATCH] Refactoring and re-plumbing. Things now... work (mostly) Created generic 'panels', of which kiwi.model.Server and kiwi.model.Panel are sub-types of. Server tab/panel is back, the MOTD and things not addressed to a channel that we're on go there. Some issues remain. For some reason the topic is a bit dodgy. /part-ing doesn't work properly for instance. --- client/js/front.events.js | 153 +++++++++++++++++--------------------- client/js/front.js | 99 +++++++++++++----------- client/js/gateway.js | 4 +- client/js/model.js | 84 +++++++++++++++------ client/js/util.js | 49 ++++++------ client/js/view.js | 44 ++++++++--- 6 files changed, 250 insertions(+), 183 deletions(-) mode change 100644 => 100755 client/js/gateway.js diff --git a/client/js/front.events.js b/client/js/front.events.js index 0fc3d63..cf02cf3 100755 --- a/client/js/front.events.js +++ b/client/js/front.events.js @@ -63,9 +63,7 @@ kiwi.front.events = { return; } - var chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === plugin_event.destination; - }); + var chan = kiwi.channels.getByName(plugin_event.destination); if (chan) { chan.addMsg(null, plugin_event.nick, plugin_event.msg); } @@ -98,11 +96,11 @@ kiwi.front.events = { destination = data.channel; } - var chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === plugin_event.destination; - }); + var chan = kiwi.channels.getByName(destination); if (chan) { chan.addMsg(null, ' ', '* ' + data.nick + ' ' + data.msg, 'action', 'color:#555;'); + } else { + kiwi.channels.server.addMsg(null, ' ', '* ' + data.nick + ' ' + data.msg, 'action', 'color:#555;'); } }, @@ -112,12 +110,10 @@ kiwi.front.events = { * @param {Object} data The event data */ onTopic: function (e, data) { - var chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + var chan = kiwi.channels.getByName(data.channel); if (chan) { chan.set({"topic": data.topic}); - chan.trigger("topic"); + chan.addMsg(null, ' ', '=== Topic for ' + data.channel + ' is: ' + data.topic, 'topic'); } }, @@ -128,11 +124,11 @@ kiwi.front.events = { */ onTopicSetBy: function (e, data) { var when, - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); - when = new Date(data.when * 1000).toLocaleString(); - chan.addMsg(null, '', 'Topic set by ' + data.nick + ' at ' + when, 'topic'); + chan = kiwi.channels.getByName(data.channel); + if (chan) { + when = new Date(data.when * 1000).toLocaleString(); + chan.addMsg(null, '', 'Topic set by ' + data.nick + ' at ' + when, 'topic'); + } }, /** @@ -145,11 +141,11 @@ kiwi.front.events = { enick = '[' + nick + ']', chan; - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + chan = kiwi.channels.getByName(data.channel); if (chan) { chan.addMsg(null, enick, data.msg, 'notice'); + } else { + kiwi.channels.server.addMsg(null, enick, data.msg, 'notice'); } }, @@ -171,7 +167,8 @@ kiwi.front.events = { kiwi.gateway.ctcp(false, 'TIME', data.nick, (new Date()).toLocaleString()); break; } - Tabview.getServerTab().addMsg(null, 'CTCP Request', '[from ' + data.nick + '] ' + data.msg, 'ctcp'); + kiwi.channels.server.addMsg(null, 'CTCP Request', '[from ' + data.nick + '] ' + data.msg, 'ctcp'); + }, /** @@ -180,7 +177,7 @@ kiwi.front.events = { * @param {Object} data The event data */ onCTCPResponse: function (e, data) { - Tabview.getServerTab().addMsg(null, 'CTCP Reply', '[from ' + data.nick + '] ' + data.msg, 'ctcp'); + kiwi.channels.server.addMsg(null, 'CTCP Reply', '[from ' + data.nick + '] ' + data.msg, 'ctcp'); }, /** @@ -225,13 +222,13 @@ kiwi.front.events = { kiwi.front.ui.doLayout(); } - //Tabview.getServerTab().addMsg(null, ' ', '=== Connected OK :)', 'status'); - //if (typeof init_data.channel === "string") { - // kiwi.front.joinChannel(init_data.channel); - //} + kiwi.channels.server.addMsg(null, ' ', '=== Connected OK :)', 'status'); + if (typeof init_data.channel === "string") { + kiwi.front.joinChannel(init_data.channel); + } kiwi.plugs.run('connect', {success: true}); } else { - //Tabview.getServerTab().addMsg(null, ' ', '=== Failed to connect :(', 'status'); + kiwi.channels.server.addMsg(null, ' ', '=== Failed to connect :(', 'status'); kiwi.plugs.run('connect', {success: false}); } @@ -245,7 +242,7 @@ kiwi.front.events = { */ onConnectFail: function (e, data) { var reason = (typeof data.reason === 'string') ? data.reason : ''; - //Tabview.getServerTab().addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error'); + kiwi.channels.server.addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error'); kiwi.plugs.run('connect', {success: false}); }, /** @@ -308,7 +305,7 @@ kiwi.front.events = { */ onOptions: function (e, data) { if (typeof kiwi.gateway.network_name === "string" && kiwi.gateway.network_name !== "") { - //Tabview.getServerTab().setTabText(kiwi.gateway.network_name); + kiwi.channels.server.set({"name": kiwi.gateway.network_name}); } }, /** @@ -317,7 +314,7 @@ kiwi.front.events = { * @param {Object} data The event data */ onMOTD: function (e, data) { - //Tabview.getServerTab().addMsg(null, data.server, data.msg, 'motd'); + kiwi.channels.server.addMsg(null, data.server, data.msg, 'motd'); }, /** * Handles the whois event @@ -337,18 +334,18 @@ kiwi.front.events = { idle_time = idle_time.h.toString().lpad(2, "0") + ':' + idle_time.m.toString().lpad(2, "0") + ':' + idle_time.s.toString().lpad(2, "0"); } - //tab = Tabview.getCurrentTab(); - //if (data.msg) { - // tab.addMsg(null, data.nick, data.msg, 'whois'); - //} else if (data.logon) { - // d = new Date(); - // d.setTime(data.logon * 1000); - // d = d.toLocaleString(); - - // tab.addMsg(null, data.nick, 'idle for ' + idle_time + ', signed on ' + d, 'whois'); - //} else { - // tab.addMsg(null, data.nick, 'idle for ' + idle_time, 'whois'); - //} + tab = kiwi.currentPanel; + if (data.msg) { + tab.addMsg(null, data.nick, data.msg, 'whois'); + } else if (data.logon) { + d = new Date(); + d.setTime(data.logon * 1000); + d = d.toLocaleString(); + + tab.addMsg(null, data.nick, 'idle for ' + idle_time + ', signed on ' + d, 'whois'); + } else { + tab.addMsg(null, data.nick, 'idle for ' + idle_time, 'whois'); + } }, /** * Handles the mode event @@ -358,9 +355,7 @@ kiwi.front.events = { onMode: function (e, data) { var tab, mem; if ((typeof data.channel === 'string') && (typeof data.effected_nick === 'string')) { - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + chan = kiwi.channels.getByName(data.channel); if (chan) { chan.addMsg(null, ' ', '[' + data.mode + '] ' + data.effected_nick + ' by ' + data.nick, 'mode', ''); mem = _.detect(chan.get("members"), function (m) { @@ -384,9 +379,7 @@ kiwi.front.events = { */ onUserList: function (e, data) { var tab, chan; - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + chan = kiwi.channels.getByName(data.channel); if (chan) { if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) { if (!kiwi.front.cache.userlist) { @@ -412,9 +405,7 @@ kiwi.front.events = { kiwi.front.cache.userlist = {}; } kiwi.front.cache.userlist.updating = false; - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + chan = kiwi.channels.getByName(data.channel); if (chan) { chan.get("members").trigger("change"); } @@ -470,18 +461,15 @@ kiwi.front.events = { * @param {Object} data The event data */ onJoin: function (e, data) { - var chan; - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + var chan = kiwi.channels.getByName(data.channel); if (!chan) { chan = new kiwi.model.Channel({"name": data.channel.toLowerCase()}); - kiwi.bbchans.add(chan); + kiwi.channels.add(chan); // No need to add ourselves to the MemberList as RPL_NAMESREPLY will be next + chan.view.show(); } else { chan.get("members").add(new kiwi.model.Member({"nick": data.nick, "modes": [], "ident": data.ident, "hostname": data.hostname})); } - chan.view.show(); }, /** * Handles the part event @@ -490,9 +478,7 @@ kiwi.front.events = { */ onPart: function (e, data) { var chan, members, cid; - chan = kiwi.bbchans.detect(function (c) { - return c.get("name") === data.channel; - }); + chan = kiwi.channels.getByName(data.channel); if (chan) { if (data.nick === kiwi.gateway.nick) { chan.trigger("close"); @@ -510,20 +496,18 @@ kiwi.front.events = { * @param {Object} data The event data */ onKick: function (e, data) { - //var tab = Tabview.getTab(data.channel); - //if (tab) { - // // If this is us, close the tabview - // if (data.kicked === kiwi.gateway.nick) { - // //tab.close(); - // tab.addMsg(null, ' ', '=== You have been kicked from ' + data.channel + '. ' + data.message, 'status kick'); - // tab.safe_to_close = true; - // tab.userlist.remove(); - // return; - // } - - // tab.addMsg(null, ' ', '<-- ' + data.kicked + ' kicked by ' + data.nick + '(' + data.message + ')', 'action kick', 'color:#990000;'); - // tab.userlist.removeUser(data.nick); - //} + var panel = kiwi.channels.getByName(data.channel); + if (panel) { + // If this is us, close the panel + if (data.kicked === kiwi.gateway.nick) { + kiwi.channels.remove(panel); + kiwi.channels.server.addMsg(null, ' ', '=== You have been kicked from ' + data.channel + '. ' + data.message, 'status kick'); + return; + } + + panel.addMsg(null, ' ', '<-- ' + data.kicked + ' kicked by ' + data.nick + '(' + data.message + ')', 'action kick', 'color:#990000;'); + panel.userlist.removeUser(data.nick); + } }, /** * Handles the nick event @@ -531,17 +515,20 @@ kiwi.front.events = { * @param {Object} data The event data */ onNick: function (e, data) { - //if (data.nick === kiwi.gateway.nick) { - // kiwi.gateway.nick = data.newnick; - // kiwi.front.ui.doLayout(); - //} + if (data.nick === kiwi.gateway.nick) { + kiwi.gateway.nick = data.newnick; + kiwi.front.ui.doLayout(); + } - //_.each(Tabview.getAllTabs(), function (tab) { - // if (tab.userlist.hasUser(data.nick)) { - // tab.userlist.renameUser(data.nick, data.newnick); - // tab.addMsg(null, ' ', '=== ' + data.nick + ' is now known as ' + data.newnick, 'action changenick'); - // } - //}); + kiwi.channels.each(function (panel) { + if (panel.isChannel) { + var member = panel.get("members").getByNick(data.nick); + if (member) { + member.set({"nick": data.newnick}); + panel.addMsg(null, ' ', '=== ' + data.nick + ' is now known as ' + data.newnick, 'action changenick'); + } + } + }); }, /** * Handles the quit event @@ -550,7 +537,7 @@ kiwi.front.events = { */ onQuit: function (e, data) { var chan, members, member; - kiwi.bbchans.forEach(function (chan) { + kiwi.channels.forEach(function (chan) { members = chan.get("members"); member = members.detect(function (m) { return data.nick === m.get("nick"); diff --git a/client/js/front.js b/client/js/front.js index 4dba63b..005cffa 100755 --- a/client/js/front.js +++ b/client/js/front.js @@ -101,7 +101,10 @@ kiwi.front = { console.log('whoaa'); } - Tabview.getCurrentTab().userlist.setWidth(new_width); + var members = kiwi.currentPanel.get("members"); + if (members) { + $(members.view.el).width(new_width); + } $('#windows').css('right', ul.outerWidth(true)); }}); @@ -128,9 +131,12 @@ kiwi.front = { kiwi.front.ui.doLayout(); try { - tmp = '/connect ' + netsel.val() + ' ' + netport.val() + ' '; - tmp += (netssl.is(':checked') ? 'true' : 'false') + ' ' + netpass.val(); - kiwi.front.run(tmp); + kiwi.gateway.connect(netsel.val(), netport.val(), netssl.is(':checked'), netpass.val(), function () { + setTimeout(function () { + kiwi.channels.server.set({"name": netsel.val()}); + kiwi.channels.view.render(); + }, 0); + }); } catch (e) { console.log(e); } @@ -168,8 +174,7 @@ kiwi.front = { kiwi.front.ui.doLayout(); kiwi.front.ui.barsHide(); - kiwi.bbchans = new kiwi.model.ChannelList(); - kiwi.bbtabs = new kiwi.view.Tabs({"el": $('#kiwi .windowlist ul')[0], "model": kiwi.bbchans}); + kiwi.channels = new kiwi.model.PanelList(); //server_tabview = new Tabview('server'); @@ -224,8 +229,9 @@ kiwi.front = { var chan, text; text = $(this).text(); if (text !== kiwi.front.cache.original_topic) { - //chan = Tabview.getCurrentTab().name; - //kiwi.gateway.topic(chan, text); + if (kiwi.currentPanel.isChannel) { + kiwi.gateway.topic(kiwi.currentPannel.get("name"), text); + } } }); @@ -256,16 +262,13 @@ kiwi.front = { var chans = chan_name.split(','), i, chan, - tab; + panel; for (i in chans) { chan = chans[i]; - //tab = Tabview.getTab(chan); - //if ((!tab) || (tab.safe_to_close === true)) { + panel = kiwi.channels.getByName(chan); + if (!panel) { kiwi.gateway.join(chan); - //tab = new Tabview(chan); - //} else { - // tab.show(); - //} + } } }, @@ -274,7 +277,7 @@ kiwi.front = { * @param {String} msg The message string to parse */ run: function (msg) { - var parts, dest, t, pos, textRange, plugin_event, msg_sliced, tab, nick; + var parts, dest, t, pos, textRange, plugin_event, msg_sliced, tab, nick, panel; // Run through any plugins plugin_event = {command: msg}; @@ -313,7 +316,7 @@ kiwi.front = { parts[3] = true; } - //Tabview.getCurrentTab().addMsg(null, ' ', '=== Connecting to ' + parts[1] + ' on port ' + parts[2] + (parts[3] ? ' using SSL' : '') + '...', 'status'); + kiwi.channels.server.addMsg(null, ' ', '=== Connecting to ' + parts[1] + ' on port ' + parts[2] + (parts[3] ? ' using SSL' : '') + '...', 'status'); console.log('Connecting to ' + parts[1] + ' on port ' + parts[2] + (parts[3] ? ' using SSL' : '') + '...'); kiwi.gateway.connect(parts[1], parts[2], parts[3], parts[4]); break; @@ -331,11 +334,9 @@ kiwi.front = { case '/part': if (typeof parts[1] === "undefined") { - //if (Tabview.getCurrentTab().safe_to_close) { - // Tabview.getCurrentTab().close(); - //} else { - // kiwi.gateway.part(Tabview.getCurrentTab().name); - //} + if (kiwi.currentPanel.isChannel) { + kiwi.gateway.part(kiwi.currentPanel.get("name")); + } } else { kiwi.gateway.part(msg.substring(6)); } @@ -344,6 +345,10 @@ kiwi.front = { case '/names': if (typeof parts[1] !== "undefined") { kiwi.gateway.raw(msg.substring(1)); + } else { + if (kiwi.currentPanel.isChannel) { + kiwi.gateway.raw("NAMES " + kiwi.currentPanel.get("name")); + } } break; @@ -365,11 +370,11 @@ kiwi.front = { msg_sliced = msg.split(' ').slice(2).join(' '); kiwi.gateway.privmsg(parts[1], msg_sliced); - //tab = Tabview.getTab(parts[1]); - //if (!tab) { - // tab = new Tabview(parts[1]); - //} - //tab.addMsg(null, kiwi.gateway.nick, msg_sliced); + // TODO: Queries + panel = kiwi.channels.getByName(parts[1]); + if (panel) { + panel.addMsg(null, kiwi.gateway.nick, msg_sliced); + } } break; @@ -388,24 +393,28 @@ kiwi.front = { break; case '/me': - //tab = Tabview.getCurrentTab(); - //kiwi.gateway.ctcp(true, 'ACTION', tab.name, msg.substring(4)); - //tab.addMsg(null, ' ', '* ' + kiwi.gateway.nick + ' ' + msg.substring(4), 'action', 'color:#555;'); + if (kiwi.currentPanel.isChannel) { + kiwi.gateway.ctcp(true, 'ACTION', tab.name, msg.substring(4), function () { + kiwi.currentPanel.addMsg(null, ' ', '* ' + kiwi.gateway.nick + ' ' + msg.substring(4), 'action', 'color:#555;'); + }); + } + //TODO: Queries break; case '/notice': dest = parts[1]; msg = parts.slice(2).join(' '); - kiwi.gateway.notice(dest, msg); - kiwi.front.events.onNotice({}, {nick: kiwi.gateway.nick, channel: dest, msg: msg}); + kiwi.gateway.notice(dest, msg, function () { + kiwi.front.events.onNotice({}, {nick: kiwi.gateway.nick, channel: dest, msg: msg}); + }); break; - case '/win': + /*case '/win': if (parts[1] !== undefined) { kiwi.front.ui.windowsShow(parseInt(parts[1], 10)); } - break; + break;*/ case '/quit': kiwi.gateway.quit(parts.slice(1).join(' ')); @@ -425,12 +434,14 @@ kiwi.front = { t.setSelectionRange(pos, pos); } } else { - //kiwi.gateway.topic(Tabview.getCurrentTab().name, msg.split(' ', 2)[1]); + if (kiwi.currentPanel.isChannel) { + kiwi.gateway.topic(kiwi.currentPanel.get("name"), msg.split(' ', 2)[1]); + } } break; case '/kiwi': - //kiwi.gateway.ctcp(true, 'KIWI', Tabview.getCurrentTab().name, msg.substring(6)); + kiwi.gateway.ctcp(true, 'KIWI', kiwi.currentPanel.get("name"), msg.substring(6)); break; case '/ctcp': @@ -440,11 +451,12 @@ kiwi.front = { msg = parts.join(' '); console.log(parts); - kiwi.gateway.ctcp(true, t, dest, msg); - //Tabview.getServerTab().addMsg(null, 'CTCP Request', '[to ' + dest + '] ' + t + ' ' + msg, 'ctcp'); + kiwi.gateway.ctcp(true, t, dest, msg, function () { + kiwi.channels.server.addMsg(null, 'CTCP Request', '[to ' + dest + '] ' + t + ' ' + msg, 'ctcp'); + }); break; default: - //Tabview.getCurrentTab().addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1)); + kiwi.currentPanel.addMsg(null, ' ', '--> Invalid command: '+parts[0].substring(1)); kiwi.gateway.raw(msg.substring(1)); break; } @@ -454,10 +466,11 @@ kiwi.front = { if (msg.trim() === '') { return; } - //if (Tabview.getCurrentTab().name !== 'server') { - // kiwi.gateway.privmsg(Tabview.getCurrentTab().name, msg); - // Tabview.getCurrentTab().addMsg(null, kiwi.gateway.nick, msg); - //} + if (kiwi.currentPanel.isChannel) { + kiwi.gateway.privmsg(kiwi.currentPanel.get("name"), msg, function () { + kiwi.currentPanel.addMsg(null, kiwi.gateway.nick, msg); + }); + } } }, diff --git a/client/js/gateway.js b/client/js/gateway.js old mode 100644 new mode 100755 index e7a9a51..c9dbce7 --- a/client/js/gateway.js +++ b/client/js/gateway.js @@ -147,8 +147,6 @@ kiwi.gateway = { */ parse: function (item) { if (item.event !== undefined) { - $(kiwi.gateway).trigger('on' + item.event, item); - switch (item.event) { case 'options': $.each(item.options, function (name, value) { @@ -177,6 +175,8 @@ kiwi.gateway = { $(kiwi.gateway).trigger('kiwi.' + item.namespace, item.data); break; } + + $(kiwi.gateway).trigger('on' + item.event, item); } }, diff --git a/client/js/model.js b/client/js/model.js index 4e01ae3..335fd88 100755 --- a/client/js/model.js +++ b/client/js/model.js @@ -52,6 +52,11 @@ kiwi.model.MemberList = Backbone.Collection.extend({ }, initialize: function (options) { this.view = new kiwi.view.MemberList({"model": this, "name": options.name}); + }, + getByNick: function (nick) { + return this.find(function (m) { + return nick === m.get("nick"); + }); } }); @@ -128,36 +133,33 @@ kiwi.model.Member = Backbone.Model.extend({ } }); -kiwi.model.ChannelList = Backbone.Collection.extend({ - model: kiwi.model.Channel, +kiwi.model.PanelList = Backbone.Collection.extend({ + model: kiwi.model.Panel, comparator: function (chan) { return chan.get("name"); + }, + initialize: function () { + this.server = new kiwi.model.Server({"name": kiwi.gateway.network_name}); + this.view = new kiwi.view.Tabs({"el": $('#kiwi .windowlist ul')[0], "model": this}); + kiwi.currentPanel = this.server; + }, + getByName: function (name) { + return this.find(function (c) { + return name === c.get("name"); + }); } }); -// TODO: Channel modes -kiwi.model.Channel = Backbone.Model.extend({ +kiwi.model.Panel = Backbone.Model.extend({ initialize: function (attributes) { - var name = this.get("name") || "", - members; - this.view = new kiwi.view.Channel({"model": this, "name": name}); + var name = this.get("name") || ""; + this.view = new kiwi.view.Panel({"model": this, "name": name}); this.set({ - "members": new kiwi.model.MemberList({"name": this.view.htmlsafe_name}), - "name": name, "backscroll": [], - "topic": "" + "name": name }, {"silent": true}); - this.addMsg(null, ' ', '--> You have joined ' + name, 'action join', 'color:#009900;'); - members = this.get("members"); - members.bind("add", function (member) { - this.addMsg(null, ' ', '--> ' + member.get("nick") + ' [' + member.get("ident") + '@' + member.get("hostname") + '] has joined', 'action join', 'color:#009900;'); - }, this); - members.bind("remove", function (member, options) { - this.addMsg(null, ' ', '<-- ' + member.get("nick") + ' has left ' + ((options.message) ? '(' + options.message + ')' : ''), 'action join', 'color:#009900;'); - }, this); - members.bind("quit", function (args) { - this.addMsg(null, ' ', '<-- ' + args.member.get("nick") + ' has quit ' + ((args.message) ? '(' + args.message + ')' : ''), 'action join', 'color:#009900;'); - }, this); + + this.isChannel = false; }, addMsg: function (time, nick, msg, type, style) { var tmp, bs; @@ -187,4 +189,44 @@ kiwi.model.Channel = Backbone.Model.extend({ this.set({"backscroll": bs}, {silent:true}); this.trigger("msg", tmp); } +}); + +kiwi.model.Server = kiwi.model.Panel.extend({ + initialize: function (attributes) { + var name = "Server"; + this.view = new kiwi.view.Panel({"model": this, "name": name}); + this.set({ + "backscroll": [], + "name": name + }, {"silent": true}); + this.isChannel = false; + } +}); + +// TODO: Channel modes +kiwi.model.Channel = kiwi.model.Panel.extend({ + initialize: function (attributes) { + var name = this.get("name") || "", + members; + this.view = new kiwi.view.Panel({"model": this, "name": name}); + this.set({ + "members": new kiwi.model.MemberList({"name": this.view.htmlsafe_name}), + "name": name, + "backscroll": [], + "topic": "" + }, {"silent": true}); + this.addMsg(null, ' ', '--> You have joined ' + name, 'action join', 'color:#009900;'); + members = this.get("members"); + members.bind("add", function (member) { + this.addMsg(null, ' ', '--> ' + member.get("nick") + ' [' + member.get("ident") + '@' + member.get("hostname") + '] has joined', 'action join', 'color:#009900;'); + }, this); + members.bind("remove", function (member, options) { + this.addMsg(null, ' ', '<-- ' + member.get("nick") + ' has left ' + ((options.message) ? '(' + options.message + ')' : ''), 'action join', 'color:#009900;'); + }, this); + members.bind("quit", function (args) { + this.addMsg(null, ' ', '<-- ' + args.member.get("nick") + ' has quit ' + ((args.message) ? '(' + args.message + ')' : ''), 'action join', 'color:#009900;'); + }, this); + + this.isChannel = true; + } }); \ No newline at end of file diff --git a/client/js/util.js b/client/js/util.js index c9f345f..c6658dc 100755 --- a/client/js/util.js +++ b/client/js/util.js @@ -139,9 +139,9 @@ var plugins = [ { name: "activity", onaddmsg: function (event, opts) { - if (kiwi.front.cur_channel.name.toLowerCase() !== kiwi.front.tabviews[event.tabview.toLowerCase()].name) { - kiwi.front.tabviews[event.tabview].activity(); - } + //if (kiwi.front.cur_channel.name.toLowerCase() !== kiwi.front.tabviews[event.tabview.toLowerCase()].name) { + // kiwi.front.tabviews[event.tabview].activity(); + //} return event; } @@ -150,24 +150,24 @@ var plugins = [ { name: "highlight", onaddmsg: function (event, opts) { - var tab = Tabviews.getTab(event.tabview.toLowerCase()); + //var tab = Tabviews.getTab(event.tabview.toLowerCase()); // If we have a highlight... - if (event.msg.toLowerCase().indexOf(kiwi.gateway.nick.toLowerCase()) > -1) { - if (Tabview.getCurrentTab() !== tab) { - tab.highlight(); - } - if (kiwi.front.isChannel(tab.name)) { - event.msg = '' + event.msg + ''; - } - } + //if (event.msg.toLowerCase().indexOf(kiwi.gateway.nick.toLowerCase()) > -1) { + // if (Tabview.getCurrentTab() !== tab) { + // tab.highlight(); + // } + // if (kiwi.front.isChannel(tab.name)) { + // event.msg = '' + event.msg + ''; + // } + //} // If it's a PM, highlight - if (!kiwi.front.isChannel(tab.name) && tab.name !== "server" - && Tabview.getCurrentTab().name.toLowerCase() !== tab.name - ) { - tab.highlight(); - } + //if (!kiwi.front.isChannel(tab.name) && tab.name !== "server" + // && Tabview.getCurrentTab().name.toLowerCase() !== tab.name + //) { + // tab.highlight(); + //} return event; } @@ -292,15 +292,16 @@ var plugins = [ return event; } - if (typeof kiwi.front.tabviews[event.tabview].nick_colours === 'undefined') { - kiwi.front.tabviews[event.tabview].nick_colours = {}; - } + //if (typeof kiwi.front.tabviews[event.tabview].nick_colours === 'undefined') { + // kiwi.front.tabviews[event.tabview].nick_colours = {}; + //} - if (typeof kiwi.front.tabviews[event.tabview].nick_colours[event.nick] === 'undefined') { - kiwi.front.tabviews[event.tabview].nick_colours[event.nick] = this.randColour(); - } + //if (typeof kiwi.front.tabviews[event.tabview].nick_colours[event.nick] === 'undefined') { + // kiwi.front.tabviews[event.tabview].nick_colours[event.nick] = this.randColour(); + //} - var c = kiwi.front.tabviews[event.tabview].nick_colours[event.nick]; + //var c = kiwi.front.tabviews[event.tabview].nick_colours[event.nick]; + var c = this.randColour(); event.nick = '' + event.nick + ''; return event; diff --git a/client/js/view.js b/client/js/view.js index 34a9b21..c971627 100755 --- a/client/js/view.js +++ b/client/js/view.js @@ -29,18 +29,17 @@ kiwi.view.MemberList = Backbone.View.extend({ } }); -kiwi.view.Channel = Backbone.View.extend({ +kiwi.view.Panel = Backbone.View.extend({ tagName: "div", className: "messages", events: { "click .chan": "chanClick" }, initialize: function (options) { - this.htmlsafe_name = 'chan_' + randomString(15); - $(this.el).attr("id", 'kiwi_window_' + this.htmlsafe_name).css('display', 'none'); + this.htmlsafe_name = 'panel_' + randomString(15); + $(this.el).attr("id", 'kiwi_panel_' + this.htmlsafe_name).css('display', 'none'); this.el = $(this.el).appendTo('#panel1 .scroller')[0]; this.model.bind('msg', this.newMsg, this); - this.model.bind('topic', this.topic, this); this.msg_count = 0; this.model.set({"view": this}, {"silent": true}); }, @@ -73,12 +72,35 @@ kiwi.view.Channel = Backbone.View.extend({ console.log(x); }, show: function () { + var $this = $(this.el); $('#panel1 .scroller').children().css('display','none'); - $(this.el).css('display', 'block'); - this.model.get("members").view.show(); - kiwi.front.ui.setTopicText(this.model.get("topic")) + $this.css('display', 'block'); + var members = this.model.get("members"); + if (members) { + members.view.show(); + } else { + $('#kiwi .userlist').children().css('display', 'none'); + } + kiwi.front.ui.setTopicText(this.model.get("topic") || "") + // TODO: Have Kiwi remember the scoll locations of each panel + $('#panel1').scrollTop($this.height()); + kiwi.currentPanel = this.model; + } +}); + +kiwi.view.Channel = kiwi.view.Panel.extend({ + initialize: function (options) { + this.htmlsafe_name = 'chan_' + randomString(15); + $(this.el).attr("id", 'kiwi_window_' + this.htmlsafe_name).css('display', 'none'); + this.el = $(this.el).appendTo('#panel1 .scroller')[0]; + this.model.bind('msg', this.newMsg, this); + this.model.bind('change[topic]', this.topic, this); + this.msg_count = 0; + this.model.set({"view": this}, {"silent": true}); + this.show(); }, topic: function (topic) { + console.log(topic); if (!topic) { topic = this.model.get("topic"); } @@ -97,25 +119,27 @@ kiwi.view.Tabs = Backbone.View.extend({ this.model.bind("add", this.addTab, this); this.model.bind("remove", this.removeTab, this); this.model.bind("reset", this.render, this); + this.model.server.bind("change", this.render, this); }, render: function () { $this = $(this.el); $this.empty(); + $('
  • ' + kiwi.gateway.network_name + '
  • ').data('pane', this.model.server).appendTo($this); this.model.forEach(function (tab) { var tabname = $(tab.get("view").el).attr("id"); - $('
  • ' + tab.get("name") + '
  • ').data('chan', tab).appendTo($this) + $('
  • ' + tab.get("name") + '
  • ').data('pane', tab).appendTo($this); }); }, addTab: function (tab) { var tabname = $(tab.get("view").el).attr("id"), $this = $(this.el); - $('
  • ' + tab.get("name") + '
  • ').data('chan', tab).appendTo($this) + $('
  • ' + tab.get("name") + '
  • ').data('pane', tab).appendTo($this); }, removeTab: function (tab) { $('#tab_' + $(tab.get("view").el).attr("id")).remove(); }, tabClick: function (e) { - $(e.currentTarget).data('chan').view.show(); + $(e.currentTarget).data('pane').view.show(); } }); -- 2.25.1