Fixed issues with NICK events

This commit is contained in:
Mattias Erming 2014-03-15 02:19:50 +01:00
parent aa40319ee9
commit 158abd7526
2 changed files with 28 additions and 13 deletions

View File

@ -160,7 +160,7 @@ $(function() {
}; };
$.fn.scrollToBottom = function() { $.fn.scrollToBottom = function() {
this.scrollTop(1e10); this.scrollTop(this.prop("scrollHeight"));
}; };
$.fn.isScrollAtBottom = function() { $.fn.isScrollAtBottom = function() {

View File

@ -362,22 +362,29 @@ function handleEvent(argv) {
break; break;
case "NICK": case "NICK":
var message = new models.Message({
user: argv.nick,
text: "changed name to " + argv.args[0],
type: "nick"
});
channels.each(function(channel) { 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") { if (typeof user !== "undefined") {
user.set("name", argv.args[0]); 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")) { if (argv.nick == network.get("nick")) {
network.set("nick", argv.args[0]); network.set({nick: argv.args[0]}, {silent: true});
} }
break; break;
@ -491,14 +498,21 @@ function handleEvent(argv) {
if (typeof rpl_namreply === "undefined") { if (typeof rpl_namreply === "undefined") {
channel.get("users").reset({silent: true}); channel.get("users").reset({silent: true});
} }
// This variable is global but will be deleted when
// rpl_endofnames is triggered..
rpl_namreply = true; rpl_namreply = true;
var names = argv.args[3].split(' '); var names = argv.args[3].split(' ');
for (var i in names) { 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( users.add(
new models.User({name: names[i]}), { user,
silent: true {silent: true}
}
); );
} }
break; break;
@ -507,6 +521,7 @@ function handleEvent(argv) {
var channel = channels.findWhere({name: argv.args[1]}); var channel = channels.findWhere({name: argv.args[1]});
var users = channel.get("users"); var users = channel.get("users");
// .. here!
delete rpl_namreply; delete rpl_namreply;
users.trigger( users.trigger(
"add", {}, users "add", {}, users