Solve nick collisions

This commit is contained in:
Mattias Erming 2014-03-14 03:00:01 +01:00
parent 0d880802a9
commit cc4b6cdfe5
2 changed files with 56 additions and 24 deletions

View file

@ -110,9 +110,28 @@ $(function() {
});
}
var timer;
var resizing = false;
$(window).on("resize", function() {
// This will prevent the scroll event from triggering
// while resizing the window.
resizing = true;
clearTimeout(timer);
timer = setTimeout(function() {
resizing = false;
}, 100);
if (sticky) {
self.scrollToBottom();
}
});
var sticky = false;
self.on("scroll", function() {
if (!resizing) {
sticky = self.isScrollAtBottom();
}
});
self.trigger("scroll");
self.on("append", function() {

View file

@ -188,9 +188,10 @@ function handleEvent(argv) {
switch (event) {
case "ERROR":
var args = argv.args;
channels.first().get("messages").add(
new models.Message({
text: argv.args.slice(2).join(" "),
text: args[args.length - 1],
type: "error"
})
);
@ -234,21 +235,25 @@ function handleEvent(argv) {
break;
case "JOIN":
if (argv.nick == network.get("nick")) {
channels.add(
var channel = channels.findWhere({name: argv.args[0]});
if (typeof channel === "undefined") {
channel = channels.add(
new models.Channel({
name: argv.args[0]
})
);
} else {
var channel = channels.findWhere({name: argv.args[0]});
}
var users = channel.get("users");
var messages = channel.get("messages");
if (argv.nick != network.get("nick")) {
users.add(
new models.User({
name: argv.nick
})
);
var messages = channel.get("messages");
}
messages.add(
new models.Message({
user: argv.nick,
@ -256,7 +261,6 @@ function handleEvent(argv) {
type: "join"
})
);
}
break;
case "PART":
@ -286,9 +290,6 @@ function handleEvent(argv) {
user: argv.nick,
text: "changed name to " + argv.args[0]
});
if (network.get("nick") == argv.nick) {
network.set("nick", argv.nick);
}
channels.each(function(channel) {
var user = channel.get("users").findWhere({name: argv.nick});
if (typeof user !== "undefined") {
@ -296,6 +297,9 @@ function handleEvent(argv) {
channel.get("messages").add(message);
}
});
if (argv.nick == network.get("nick")) {
network.set("nick", argv.args[0]);
}
break;
case "TOPIC":
@ -327,8 +331,15 @@ function handleEvent(argv) {
case "rpl_namreply":
var names = argv.args[3].split(' ');
var channel = network.get("channels").findWhere({name: argv.args[2]});
var users = channel.get("users");
if (typeof channel === "undefined") {
channel = channels.add(
new models.Channel({
name: argv.args[2]
})
);
}
var users = channel.get("users");
if (names[0] == network.get("nick")) {
users.reset();
}
@ -349,6 +360,8 @@ function handleEvent(argv) {
);
break;
case "001": // `registered`
network.set("nick", argv.args[0]);
case "rpl_motdstart":
case "rpl_endofmotd":
case "rpl_motd":