From 087ae21137fa2f9e91557e2bdbe5cd99aeb9cffe Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sun, 6 Apr 2014 22:53:07 +0200 Subject: [PATCH] Allow calling /part from queries --- client/js/chat.js | 18 +++++++++++++----- lib/server.js | 18 ++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/client/js/chat.js b/client/js/chat.js index 632f7d67..ea0f7114 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -175,18 +175,26 @@ $(function() { input.val(""); socket.emit("input", { id: input.data("target"), - text: text + text: text, }); }); + chat.on("click", ".close", function() { + var id = parseInt($(this).closest(".window").attr("id").replace("window-", "")); + socket.emit("input", { + id: id, + text: "/part", + }); + }); + + chat.on("click", ".user", function(e) { + e.preventDefault(); + }); + chat.on("focus", "input[type=text]", function() { $(this).closest(".window").find(".messages").scrollToBottom(); }); - chat.on("click", ".user", function(e) { - e.preventDefault(); - }); - var highest = 1; $.fn.bringToTop = function() { return this.css('z-index', highest++) diff --git a/lib/server.js b/lib/server.js index f6d5945f..19f100df 100644 --- a/lib/server.js +++ b/lib/server.js @@ -130,13 +130,21 @@ function input(json) { break; case "join": - case "part": case "nick": if (client && args[1]) { client[cmd].apply(client, args.slice(1)); } break; + case "leave": + case "part": + if (channel.get("type") == "query") { + network.get("channels").remove(channel); + } else if (client) { + client.part(channel.get("name")); + } + break; + case "topic": var chan = channel.get("name"); if (client) { @@ -205,12 +213,10 @@ function event(event, data) { var chan = channels.findWhere({name: data[0].channel}); var users = chan.get("users"); - if (data[0].client == this.get("client").me) { - users.reset(); + if (data[0].client != this.get("client").me) { + users.remove(users.findWhere({name: data[0].client})); } else { - users.remove( - users.findWhere({name: data[0].client}) - ); + users.reset(); } chan.addMessage({