diff --git a/client/js/chat.js b/client/js/chat.js index a2f3fbcd..6b6e5e9c 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -160,7 +160,7 @@ $(function() { }; $.fn.scrollToBottom = function() { - this.scrollTop(1e10); + this.scrollTop(this.prop("scrollHeight")); }; $.fn.isScrollAtBottom = function() { diff --git a/lib/server.js b/lib/server.js index ca3a0000..8bb9953c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -362,22 +362,29 @@ function handleEvent(argv) { break; case "NICK": - var message = new models.Message({ - user: argv.nick, - text: "changed name to " + argv.args[0], - type: "nick" - }); - channels.each(function(channel) { - var user = channel.get("users").findWhere({name: argv.nick}); + var users = channel.get("users"); + var messages = channel.get("messages"); + + var user = users.findWhere({name: argv.nick}); if (typeof user !== "undefined") { user.set("name", argv.args[0]); - channel.get("messages").add(message); + + users.sort(); + users.trigger( + "change", {}, users + ); + + messages.add(new models.Message({ + user: argv.nick, + text: "changed name to " + argv.args[0], + type: "nick" + })); } }); if (argv.nick == network.get("nick")) { - network.set("nick", argv.args[0]); + network.set({nick: argv.args[0]}, {silent: true}); } break; @@ -491,14 +498,21 @@ function handleEvent(argv) { if (typeof rpl_namreply === "undefined") { channel.get("users").reset({silent: true}); } + + // This variable is global but will be deleted when + // rpl_endofnames is triggered.. rpl_namreply = true; var names = argv.args[3].split(' '); for (var i in names) { + var mode = (names[i].match(/^\W/) || "").toString(); + var user = new models.User({ + mode: mode, + name: names[i].replace(mode, '') + }); users.add( - new models.User({name: names[i]}), { - silent: true - } + user, + {silent: true} ); } break; @@ -507,6 +521,7 @@ function handleEvent(argv) { var channel = channels.findWhere({name: argv.args[1]}); var users = channel.get("users"); + // .. here! delete rpl_namreply; users.trigger( "add", {}, users