diff --git a/client/js/chat.js b/client/js/chat.js index d5ae48fd..85829c60 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -101,7 +101,7 @@ $(function() { }; $.fn.scrollToBottom = function() { - this.scrollTop(this.prop("scrollHeight")); + this.scrollTop(1e10); }; $.fn.isScrollAtBottom = function() { diff --git a/lib/models.js b/lib/models.js index 2b300f5e..43294f67 100644 --- a/lib/models.js +++ b/lib/models.js @@ -45,19 +45,19 @@ models.Channel = Backbone.Model.extend({ this.set("users", new models.UserCollection()); this.get("users").on( "all", - function() { + function(e) { // Bubble event - this.trigger("change", this); + this.trigger("user", this); }, this ); this.set("messages", new models.MessageCollection()); this.get("messages").on( - "all", + "add", function() { // Bubble event - this.trigger("change", this); + this.trigger("message", this); }, this ); @@ -82,9 +82,9 @@ models.Network = Backbone.Model.extend({ this.set("channels", new models.ChannelCollection()); this.get("channels").on( "all", - function() { + function(type) { // Bubble event - this.trigger("change", this); + this.trigger(type == "user" || type == "message" ? type : "channel", this); }, this ); diff --git a/lib/server.js b/lib/server.js index 77f2271c..ddad9c78 100644 --- a/lib/server.js +++ b/lib/server.js @@ -16,15 +16,19 @@ Server.prototype.listen = function(port) { var http = connect() .use(connect.static("client")) .listen(port); - - this.sockets = io.listen(http).sockets; + + this.networks.on( + "all", + function(type) { + self.sockets.emit("event", self.networks); + + // Debug + console.log(type); + } + ); + + this.sockets = io.listen(http, {log: false}).sockets; this.sockets.on("connection", function(socket) { - self.networks.on( - "all", - function() { - self.sockets.emit("event", self.networks); - } - ); socket.emit( "event", self.networks @@ -92,4 +96,7 @@ function handleEvent(argv) { text: argv.args[1] }) ); + + // Debug + console.log(argv); }