From ce119b06b6e8205f42f14c89b7612a177125f169 Mon Sep 17 00:00:00 2001 From: Jack Allnutt Date: Mon, 30 Jan 2012 04:19:31 +0000 Subject: [PATCH] Channel member list functional, joins, parts, quits & channel user modes work, topic now displays. Overall, a lot more now works again! --- client/js/front.events.js | 89 +++++++++++++-------------------------- client/js/front.ui.js | 2 +- client/js/model.js | 26 +++++++++--- client/js/util.js | 4 +- client/js/view.js | 25 +++++++++-- 5 files changed, 75 insertions(+), 71 deletions(-) diff --git a/client/js/front.events.js b/client/js/front.events.js index e0d6a59..0fc3d63 100755 --- a/client/js/front.events.js +++ b/client/js/front.events.js @@ -117,6 +117,7 @@ kiwi.front.events = { }); if (chan) { chan.set({"topic": data.topic}); + chan.trigger("topic"); } }, @@ -357,11 +358,6 @@ kiwi.front.events = { onMode: function (e, data) { var tab, mem; if ((typeof data.channel === 'string') && (typeof data.effected_nick === 'string')) { - // tab = Tabview.getTab(data.channel); - // tab.addMsg(null, ' ', '[' + data.mode + '] ' + data.effected_nick + ' by ' + data.nick, 'mode', ''); - // if (tab.userlist.hasUser(data.effected_nick)) { - // tab.userlist.changeUserMode(data.effected_nick, data.mode.substr(1), (data.mode[0] === '+')); - // } chan = kiwi.bbchans.detect(function (c) { return c.get("name") === data.channel; }); @@ -388,27 +384,21 @@ kiwi.front.events = { */ onUserList: function (e, data) { var tab, chan; - - //tab = Tabview.getTab(data.channel); - //if (!tab) { - // return; - //} - chan = kiwi.bbchans.detect(function (c) { return c.get("name") === data.channel; }); - if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) { - if (!kiwi.front.cache.userlist) { - kiwi.front.cache.userlist = {updating: true}; - } else { - kiwi.front.cache.userlist.updating = true; - } - chan.get("members").reset(); - } - - //tab.userlist.addUser(data.users); if (chan) { - chan.get("members").add(data.users, {"silent": true}); + if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) { + if (!kiwi.front.cache.userlist) { + kiwi.front.cache.userlist = {updating: true}; + } else { + kiwi.front.cache.userlist.updating = true; + } + chan.get("members").reset([],{"silent": true}); + } + _.forEach(data.users, function (u) { + chan.get("members").add(new kiwi.model.Member(u), {"silent": true}); + }); } }, /** @@ -417,6 +407,7 @@ kiwi.front.events = { * @param {Object} data The event data */ onUserListEnd: function (e, data) { + var chan; if (!kiwi.front.cache.userlist) { kiwi.front.cache.userlist = {}; } @@ -479,30 +470,18 @@ kiwi.front.events = { * @param {Object} data The event data */ onJoin: function (e, data) { - //var tab = Tabview.getTab(data.channel); - //if (!tab) { - // tab = new Tabview(data.channel.toLowerCase()); - //} - - //tab.addMsg(null, ' ', '--> ' + data.nick + ' [' + data.ident + '@' + data.hostname + '] has joined', 'action join', 'color:#009900;'); - + var chan; chan = kiwi.bbchans.detect(function (c) { return c.get("name") === data.channel; }); if (!chan) { chan = new kiwi.model.Channel({"name": data.channel.toLowerCase()}); - chan.get("members").add(new kiwi.model.Member({"nick": data.nick, "modes": []})); kiwi.bbchans.add(chan); + // No need to add ourselves to the MemberList as RPL_NAMESREPLY will be next } else { - chan.get("members").add(data.users, {"silent": true}); + chan.get("members").add(new kiwi.model.Member({"nick": data.nick, "modes": [], "ident": data.ident, "hostname": data.hostname})); } chan.view.show(); - - //if (data.nick === kiwi.gateway.nick) { - // return; // Not needed as it's already in nicklist - //} - - //tab.userlist.addUser({nick: data.nick, modes: []}); }, /** * Handles the part event @@ -510,19 +489,7 @@ kiwi.front.events = { * @param {Object} data The event data */ onPart: function (e, data) { - var chan, members; - //var tab = Tabview.getTab(data.channel); - //if (tab) { - // If this is us, close the tabview - // if (data.nick === kiwi.gateway.nick) { - // tab.close(); - // Tabview.getServerTab().show(); - // return; - // } - - // tab.addMsg(null, ' ', '<-- ' + data.nick + ' has left (' + data.message + ')', 'action part', 'color:#990000;'); - // tab.userlist.removeUser(data.nick); - //} + var chan, members, cid; chan = kiwi.bbchans.detect(function (c) { return c.get("name") === data.channel; }); @@ -530,11 +497,10 @@ kiwi.front.events = { if (data.nick === kiwi.gateway.nick) { chan.trigger("close"); } else { - chan.addMsg(null, ' ', '<-- ' + data.nick + ' has left (' + data.message + ')', 'action part', 'color:#990000;'); members = chan.get("members"); - members.remove(_.detect(members, function (m) { + members.remove(members.detect(function (m) { return data.nick === m.get("nick"); - })); + }).cid, {"message": data.message}) } } }, @@ -583,12 +549,17 @@ kiwi.front.events = { * @param {Object} data The event data */ onQuit: function (e, data) { - //_.each(Tabview.getAllTabs(), function (tab) { - // if (tab.userlist.hasUser(data.nick)) { - // tab.userlist.removeUser(data.nick); - // tab.addMsg(null, ' ', '<-- ' + data.nick + ' has quit (' + data.message + ')', 'action quit', 'color:#990000;'); - // } - //}); + var chan, members, member; + kiwi.bbchans.forEach(function (chan) { + members = chan.get("members"); + member = members.detect(function (m) { + return data.nick === m.get("nick"); + }); + if (member) { + members.trigger("quit", {"member": member, "message": data.message}); + members.remove(member.cid); + } + }); }, /** * Handles the channelRedirect event diff --git a/client/js/front.ui.js b/client/js/front.ui.js index e7d2eb4..feabb51 100755 --- a/client/js/front.ui.js +++ b/client/js/front.ui.js @@ -396,7 +396,7 @@ kiwi.front.ui = { return; } i++; - }*/ + } }, diff --git a/client/js/model.js b/client/js/model.js index d5d490a..4e01ae3 100755 --- a/client/js/model.js +++ b/client/js/model.js @@ -49,6 +49,9 @@ kiwi.model.MemberList = Backbone.Collection.extend({ console.log('Something\'s gone wrong somewhere - two users have the same nick!'); return 0; } + }, + initialize: function (options) { + this.view = new kiwi.view.MemberList({"model": this, "name": options.name}); } }); @@ -81,8 +84,7 @@ kiwi.model.Member = Backbone.Model.extend({ modes = this.get("modes"); modes = modes || []; - modes.sort(this.sortModes); - + this.sortModes(modes); this.set({"nick": nick, "modes": modes, "prefix": this.getPrefix(modes)}, {silent: true}); }, addMode: function (mode) { @@ -136,19 +138,31 @@ kiwi.model.ChannelList = Backbone.Collection.extend({ // TODO: Channel modes kiwi.model.Channel = Backbone.Model.extend({ initialize: function (attributes) { - var name = this.get("name") || ""; + var name = this.get("name") || "", + members; + this.view = new kiwi.view.Channel({"model": this, "name": name}); this.set({ - "members": new kiwi.model.MemberList(), + "members": new kiwi.model.MemberList({"name": this.view.htmlsafe_name}), "name": name, "backscroll": [], "topic": "" }, {"silent": true}); - this.view = new kiwi.view.Channel({"model": this, "name": name}); + 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); }, addMsg: function (time, nick, msg, type, style) { var tmp, bs; - tmp = {"msg": msg, "time": time, "nick": nick, "chan": this.get("name")}; + tmp = {"msg": msg, "time": time, "nick": nick, "chan": this.get("name"), "style": style}; tmp = kiwi.plugs.run('addmsg', tmp); if (!tmp) { return; diff --git a/client/js/util.js b/client/js/util.js index fde8b60..c9f345f 100755 --- a/client/js/util.js +++ b/client/js/util.js @@ -14,7 +14,7 @@ var kiwi = {}; * @param {Boolean} debug Whether to re-enable console.log or not */ function manageDebug(debug) { - var log, consoleBackUp; +/* var log, consoleBackUp; if (window.console) { consoleBackUp = window.console.log; window.console.log = function () { @@ -30,7 +30,7 @@ function manageDebug(debug) { log(str); } }; - } + }*/ } /** diff --git a/client/js/view.js b/client/js/view.js index ac2a839..6db6e7e 100755 --- a/client/js/view.js +++ b/client/js/view.js @@ -10,17 +10,22 @@ kiwi.view.MemberList = Backbone.View.extend({ }, initialize: function (options) { $(this.el).attr("id", 'kiwi_userlist_' + options.name); - this.model.get("members").bind('change', this.render, this); + this.model.bind('all', this.render, this); + $(this.el).appendTo('#kiwi .userlist'); }, render: function () { var $this = $(this.el); $this.empty(); - this.model.get("members").forEach(function (member) { - $this.append('
  • ' + user.prefix + user.nick + '
  • '); + this.model.forEach(function (member) { + $('
  • ' + member.get("prefix") + '' + member.get("nick") + '
  • ').appendTo($this).data('member', member); }); }, nickClick: function (x) { console.log(x); + }, + show: function () { + $('#kiwi .userlist').children().css('display', 'none'); + $(this.el).css('display', 'block'); } }); @@ -35,8 +40,10 @@ kiwi.view.Channel = Backbone.View.extend({ $(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('topic', this.topic, this); this.msg_count = 0; this.model.set({"view": this}, {"silent": true}); + this.visible = false; }, render: function () { var $this = $(this.el); @@ -44,6 +51,7 @@ kiwi.view.Channel = Backbone.View.extend({ this.model.get("backscroll").forEach(this.newMsg); }, newMsg: function (msg) { + // TODO: make sure that the message pane is scrolled to the bottom var re, line_msg, $this = $(this.el); // Make the channels clickable re = new RegExp('\\B(' + kiwi.gateway.channel_prefix + '[^ ,.\\007]+)', 'g'); @@ -68,6 +76,17 @@ kiwi.view.Channel = Backbone.View.extend({ show: function () { $('#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")) + }, + topic: function (topic) { + if (!topic) { + topic = this.model.get("topic"); + } + this.model.addMsg(null, ' ', '=== Topic for ' + this.model.get("name") + ' is: ' + topic, 'topic'); + if ($(this.el).css('display') === 'block') { + kiwi.front.ui.setTopicText(this.model.get("topic")) + } } }); -- 2.25.1