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() {
sticky = self.isScrollAtBottom();
if (!resizing) {
sticky = self.isScrollAtBottom();
}
});
self.trigger("scroll");
self.on("append", function() {

View file

@ -8,7 +8,7 @@ var models = require("./models.js");
module.exports = Server;
function Server() {
this.sockets = false;
this.sockets = false;
this.networks = new models.NetworkCollection;
}
@ -179,7 +179,7 @@ function handleInput(input) {
}
function handleEvent(argv) {
var network = this;
var network = this;
var channels = network.get("channels");
var event = argv.commandType != "error" ? argv.command
@ -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,29 +235,32 @@ 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 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,
text: "has joined the channel.",
type: "join"
})
);
}
messages.add(
new models.Message({
user: argv.nick,
text: "has joined the channel.",
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,10 +297,13 @@ function handleEvent(argv) {
channel.get("messages").add(message);
}
});
if (argv.nick == network.get("nick")) {
network.set("nick", argv.args[0]);
}
break;
case "TOPIC":
var channel = channels.findWhere({name: argv.args[0]});
var channel = channels.findWhere({name: argv.args[0]});
var messages = channel.get("messages");
messages.add(
new models.Message({
@ -325,10 +329,17 @@ function handleEvent(argv) {
break;
case "rpl_namreply":
var names = argv.args[3].split(' ');
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":