});\r
if (chan) {\r
chan.set({"topic": data.topic});\r
+ chan.trigger("topic");\r
}\r
},\r
\r
onMode: function (e, data) {\r
var tab, mem;\r
if ((typeof data.channel === 'string') && (typeof data.effected_nick === 'string')) {\r
- // tab = Tabview.getTab(data.channel);\r
- // tab.addMsg(null, ' ', '[' + data.mode + '] ' + data.effected_nick + ' by ' + data.nick, 'mode', '');\r
- // if (tab.userlist.hasUser(data.effected_nick)) {\r
- // tab.userlist.changeUserMode(data.effected_nick, data.mode.substr(1), (data.mode[0] === '+'));\r
- // }\r
chan = kiwi.bbchans.detect(function (c) {\r
return c.get("name") === data.channel;\r
});\r
*/\r
onUserList: function (e, data) {\r
var tab, chan;\r
-\r
- //tab = Tabview.getTab(data.channel);\r
- //if (!tab) {\r
- // return;\r
- //}\r
-\r
chan = kiwi.bbchans.detect(function (c) {\r
return c.get("name") === data.channel;\r
});\r
- if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) {\r
- if (!kiwi.front.cache.userlist) {\r
- kiwi.front.cache.userlist = {updating: true};\r
- } else {\r
- kiwi.front.cache.userlist.updating = true;\r
- }\r
- chan.get("members").reset();\r
- }\r
-\r
- //tab.userlist.addUser(data.users);\r
if (chan) {\r
- chan.get("members").add(data.users, {"silent": true});\r
+ if ((!kiwi.front.cache.userlist) || (!kiwi.front.cache.userlist.updating)) {\r
+ if (!kiwi.front.cache.userlist) {\r
+ kiwi.front.cache.userlist = {updating: true};\r
+ } else {\r
+ kiwi.front.cache.userlist.updating = true;\r
+ }\r
+ chan.get("members").reset([],{"silent": true});\r
+ }\r
+ _.forEach(data.users, function (u) {\r
+ chan.get("members").add(new kiwi.model.Member(u), {"silent": true});\r
+ });\r
}\r
},\r
/**\r
* @param {Object} data The event data\r
*/\r
onUserListEnd: function (e, data) {\r
+ var chan;\r
if (!kiwi.front.cache.userlist) {\r
kiwi.front.cache.userlist = {};\r
}\r
* @param {Object} data The event data\r
*/\r
onJoin: function (e, data) {\r
- //var tab = Tabview.getTab(data.channel);\r
- //if (!tab) {\r
- // tab = new Tabview(data.channel.toLowerCase());\r
- //}\r
-\r
- //tab.addMsg(null, ' ', '--> ' + data.nick + ' [' + data.ident + '@' + data.hostname + '] has joined', 'action join', 'color:#009900;');\r
-\r
+ var chan;\r
chan = kiwi.bbchans.detect(function (c) {\r
return c.get("name") === data.channel;\r
});\r
if (!chan) {\r
chan = new kiwi.model.Channel({"name": data.channel.toLowerCase()});\r
- chan.get("members").add(new kiwi.model.Member({"nick": data.nick, "modes": []}));\r
kiwi.bbchans.add(chan);\r
+ // No need to add ourselves to the MemberList as RPL_NAMESREPLY will be next\r
} else {\r
- chan.get("members").add(data.users, {"silent": true});\r
+ chan.get("members").add(new kiwi.model.Member({"nick": data.nick, "modes": [], "ident": data.ident, "hostname": data.hostname}));\r
}\r
chan.view.show();\r
-\r
- //if (data.nick === kiwi.gateway.nick) {\r
- // return; // Not needed as it's already in nicklist\r
- //}\r
-\r
- //tab.userlist.addUser({nick: data.nick, modes: []});\r
},\r
/**\r
* Handles the part event\r
* @param {Object} data The event data\r
*/\r
onPart: function (e, data) {\r
- var chan, members;\r
- //var tab = Tabview.getTab(data.channel);\r
- //if (tab) {\r
- // If this is us, close the tabview\r
- // if (data.nick === kiwi.gateway.nick) {\r
- // tab.close();\r
- // Tabview.getServerTab().show();\r
- // return;\r
- // }\r
-\r
- // tab.addMsg(null, ' ', '<-- ' + data.nick + ' has left (' + data.message + ')', 'action part', 'color:#990000;');\r
- // tab.userlist.removeUser(data.nick);\r
- //}\r
+ var chan, members, cid;\r
chan = kiwi.bbchans.detect(function (c) {\r
return c.get("name") === data.channel;\r
});\r
if (data.nick === kiwi.gateway.nick) {\r
chan.trigger("close");\r
} else {\r
- chan.addMsg(null, ' ', '<-- ' + data.nick + ' has left (' + data.message + ')', 'action part', 'color:#990000;');\r
members = chan.get("members");\r
- members.remove(_.detect(members, function (m) {\r
+ members.remove(members.detect(function (m) {\r
return data.nick === m.get("nick");\r
- }));\r
+ }).cid, {"message": data.message})\r
}\r
}\r
},\r
* @param {Object} data The event data\r
*/\r
onQuit: function (e, data) {\r
- //_.each(Tabview.getAllTabs(), function (tab) {\r
- // if (tab.userlist.hasUser(data.nick)) {\r
- // tab.userlist.removeUser(data.nick);\r
- // tab.addMsg(null, ' ', '<-- ' + data.nick + ' has quit (' + data.message + ')', 'action quit', 'color:#990000;');\r
- // }\r
- //});\r
+ var chan, members, member;\r
+ kiwi.bbchans.forEach(function (chan) {\r
+ members = chan.get("members");\r
+ member = members.detect(function (m) {\r
+ return data.nick === m.get("nick");\r
+ });\r
+ if (member) {\r
+ members.trigger("quit", {"member": member, "message": data.message});\r
+ members.remove(member.cid);\r
+ }\r
+ });\r
},\r
/**\r
* Handles the channelRedirect event\r
console.log('Something\'s gone wrong somewhere - two users have the same nick!');\r
return 0;\r
}\r
+ },\r
+ initialize: function (options) {\r
+ this.view = new kiwi.view.MemberList({"model": this, "name": options.name});\r
}\r
});\r
\r
\r
modes = this.get("modes");\r
modes = modes || [];\r
- modes.sort(this.sortModes);\r
-\r
+ this.sortModes(modes);\r
this.set({"nick": nick, "modes": modes, "prefix": this.getPrefix(modes)}, {silent: true});\r
},\r
addMode: function (mode) {\r
// TODO: Channel modes\r
kiwi.model.Channel = Backbone.Model.extend({\r
initialize: function (attributes) {\r
- var name = this.get("name") || "";\r
+ var name = this.get("name") || "",\r
+ members;\r
+ this.view = new kiwi.view.Channel({"model": this, "name": name});\r
this.set({\r
- "members": new kiwi.model.MemberList(),\r
+ "members": new kiwi.model.MemberList({"name": this.view.htmlsafe_name}),\r
"name": name,\r
"backscroll": [],\r
"topic": ""\r
}, {"silent": true});\r
- this.view = new kiwi.view.Channel({"model": this, "name": name});\r
+ this.addMsg(null, ' ', '--> You have joined ' + name, 'action join', 'color:#009900;');\r
+ members = this.get("members");\r
+ members.bind("add", function (member) {\r
+ this.addMsg(null, ' ', '--> ' + member.get("nick") + ' [' + member.get("ident") + '@' + member.get("hostname") + '] has joined', 'action join', 'color:#009900;');\r
+ }, this);\r
+ members.bind("remove", function (member, options) {\r
+ this.addMsg(null, ' ', '<-- ' + member.get("nick") + ' has left ' + ((options.message) ? '(' + options.message + ')' : ''), 'action join', 'color:#009900;');\r
+ }, this);\r
+ members.bind("quit", function (args) {\r
+ this.addMsg(null, ' ', '<-- ' + args.member.get("nick") + ' has quit ' + ((args.message) ? '(' + args.message + ')' : ''), 'action join', 'color:#009900;');\r
+ }, this);\r
},\r
addMsg: function (time, nick, msg, type, style) {\r
var tmp, bs;\r
\r
- tmp = {"msg": msg, "time": time, "nick": nick, "chan": this.get("name")};\r
+ tmp = {"msg": msg, "time": time, "nick": nick, "chan": this.get("name"), "style": style};\r
tmp = kiwi.plugs.run('addmsg', tmp);\r
if (!tmp) {\r
return;\r
},\r
initialize: function (options) {\r
$(this.el).attr("id", 'kiwi_userlist_' + options.name);\r
- this.model.get("members").bind('change', this.render, this);\r
+ this.model.bind('all', this.render, this);\r
+ $(this.el).appendTo('#kiwi .userlist');\r
},\r
render: function () {\r
var $this = $(this.el);\r
$this.empty();\r
- this.model.get("members").forEach(function (member) {\r
- $this.append('<li><a class="nick"><span class="prefix">' + user.prefix + user.nick + '</a></li>');\r
+ this.model.forEach(function (member) {\r
+ $('<li><a class="nick"><span class="prefix">' + member.get("prefix") + '</span>' + member.get("nick") + '</a></li>').appendTo($this).data('member', member);\r
});\r
},\r
nickClick: function (x) {\r
console.log(x);\r
+ },\r
+ show: function () {\r
+ $('#kiwi .userlist').children().css('display', 'none');\r
+ $(this.el).css('display', 'block');\r
}\r
});\r
\r
$(this.el).attr("id", 'kiwi_window_' + this.htmlsafe_name).css('display', 'none');\r
this.el = $(this.el).appendTo('#panel1 .scroller')[0];\r
this.model.bind('msg', this.newMsg, this);\r
+ this.model.bind('topic', this.topic, this);\r
this.msg_count = 0;\r
this.model.set({"view": this}, {"silent": true});\r
+ this.visible = false;\r
},\r
render: function () {\r
var $this = $(this.el);\r
this.model.get("backscroll").forEach(this.newMsg);\r
},\r
newMsg: function (msg) {\r
+ // TODO: make sure that the message pane is scrolled to the bottom\r
var re, line_msg, $this = $(this.el);\r
// Make the channels clickable\r
re = new RegExp('\\B(' + kiwi.gateway.channel_prefix + '[^ ,.\\007]+)', 'g');\r
show: function () {\r
$('#panel1 .scroller').children().css('display','none');\r
$(this.el).css('display', 'block');\r
+ this.model.get("members").view.show();\r
+ kiwi.front.ui.setTopicText(this.model.get("topic"))\r
+ },\r
+ topic: function (topic) {\r
+ if (!topic) {\r
+ topic = this.model.get("topic");\r
+ }\r
+ this.model.addMsg(null, ' ', '=== Topic for ' + this.model.get("name") + ' is: ' + topic, 'topic');\r
+ if ($(this.el).css('display') === 'block') {\r
+ kiwi.front.ui.setTopicText(this.model.get("topic"))\r
+ }\r
}\r
});\r
\r