From 61a590751e1407cdecf0503433e8c01824a14805 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 31 Mar 2016 14:22:57 +0100 Subject: Add ability to send PMs with /msg, fixed bug with channel messages --- index.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 15a366a..3b3cbfa 100644 --- a/index.js +++ b/index.js @@ -70,10 +70,16 @@ $("#send-message").keypress(function(e) { client.whois(message.substring(7, message.length)); } else if (message.indexOf("/list") == 0) { client.list(); + } else if (message.indexOf("/msg") == 0) { + nick = message.split(" ")[1]; + message = message.substring(6+nick.length, message.length); + console.log(nick); + console.log(message); + sendPm(message, nick); } else { var tab = $(".tab.active").attr("data-tab"); if (tab.startsWith("chan-")) { - sendMsg(message, channel.replace("#","")); + sendMsg(message, channel); } else if(tab.startsWith("pm-")){ sendPm(message, tab.substring(3, tab.length)); @@ -92,18 +98,33 @@ function sendMsg(message, channel) { } function sendPm(message, nick) { + + var chanTab = $("[data-tab=pm-"+nick+"].tab"); + $(".active").removeClass("active"); + if (chanTab.length == 0) { + $(".ui.menu").append(""+nick+""); + $("#chan-container").append("
"); + chanTab = $("[data-tab=pm-"+nick+"].tab"); + chanTab.append("
"); + + $('.menu .item').tab({history:false}); + numChans++; + } + $("[data-tab=pm-"+nick+"]").addClass("active"); + var chatTab = $("[data-tab=pm-"+nick+"].chat"); console.log(nick + ': ' + message); client.say(nick, message); - var chanTab = $("[data-tab=pm-"+nick+"].chat"); - chanTab.append("

<" + "wclient" + "> " + message +"

"); - chanTab.scrollTop(chanTab.prop("scrollHeight")); + chatTab.append("

<" + myNick + "> " + message +"

"); + chatTab.scrollTop(chanTab.prop("scrollHeight")); } function joinChannel(channel) { client.join(channel); channel = channel.replace("#",""); chanId = $(".active.chat").attr("data-id") + $(".active").removeClass("active"); + $(".ui.menu").append("#"+channel+""); $("#chan-container").append("
"); -- cgit v1.2.3