From 2c8040a6ca85ce9da9c03716f277f79d096fa25d Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 29 Mar 2014 08:36:12 -0700 Subject: [PATCH] Fix event trigger bug --- client/js/chat.js | 6 ++++-- lib/models.js | 8 +++++--- lib/server.js | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/client/js/chat.js b/client/js/chat.js index cf036f9..807c7e4 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -17,8 +17,10 @@ $(function() { function event(type, json) { console.log(json); - switch (type) { + console.log(type); + switch (type) { + case "network": var html = ""; json.forEach(function(network) { @@ -81,7 +83,7 @@ $(function() { if (typeof json.target !== "undefined") { target = chat.find(".window[data-id='" + json.target + "']"); } - + var message = json.data; if (message.type == "error") { target = target.parent().find(".active"); diff --git a/lib/models.js b/lib/models.js index b6f9ca8..414860e 100644 --- a/lib/models.js +++ b/lib/models.js @@ -24,8 +24,7 @@ models.Users = Backbone.Collection.extend({ } ); - // Iterate all the modes and move users with these - // modes to the top of the collection. + // Move users with these modes to the top. var modes = ["+", "@"]; for (var i in modes) { this.models = _.remove(this.models, function(user) { @@ -108,8 +107,11 @@ models.Network = Backbone.Model.extend({ channels: new models.Channels, }); - this.get("channels").on("message user", function() { this.trigger(action, data); }, this); this.get("channels").on("all", function(action, data) { + if (action == "message" + || action == "user") { + return this.trigger(action, data); + } this.trigger("channel", { target: this.get("id"), type: "channel", diff --git a/lib/server.js b/lib/server.js index 6299a69..14c88a8 100644 --- a/lib/server.js +++ b/lib/server.js @@ -86,8 +86,10 @@ function input(json) { "msg", channel.get("name") ); - case "msg": - channel.addMessage({message: _.tail(args, 2)}); + case "msg": + channel.addMessage({ + message: _.tail(args, 2).join(" ") + }); break; case "server":