From 257deaa4e6019ba78d0f345c15443f193d777bf5 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Tue, 18 Dec 2012 17:33:16 +0100 Subject: [PATCH] improved messages management --- lib/ns_client.js | 22 ++++++++++------------ lib/nsui.js | 16 ++++++---------- lib/tab.nsui.js | 2 +- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/ns_client.js b/lib/ns_client.js index 125d859..028b9ad 100644 --- a/lib/ns_client.js +++ b/lib/ns_client.js @@ -41,20 +41,18 @@ var NsClient = function() { })(this.actions.msg.exp); this.actions.msg.act = (function(elem) { return function(msg) { - if ($cs.opts.get("enable_msg")) { - var mo = {}; + var mo = {}; - mch = elem.actions.msg.exp.exec(msg); - if (mch !== null && typeof elem.msgHandler !== "undefined") { - mo.socket = mch[1]; - mo.login = mch[2]; - mo.host = mch[3]; - mo.location = elem.msgDecode(mch[4]); - mo.group = mch[5]; - mo.message = elem.msgDecode(mch[6]); + mch = elem.actions.msg.exp.exec(msg); + if (mch !== null) { + mo.socket = mch[1]; + mo.login = mch[2]; + mo.host = mch[3]; + mo.location = elem.msgDecode(mch[4]); + mo.group = mch[5]; + mo.message = elem.msgDecode(mch[6]); - elem.msgHandler(mo); - } + $cs.ui.addContentToTab(mo.login, mo); } }; })(this); diff --git a/lib/nsui.js b/lib/nsui.js index be129d4..7512825 100644 --- a/lib/nsui.js +++ b/lib/nsui.js @@ -94,8 +94,12 @@ Nsui.prototype.addNewTab = function(tab_name) { }; Nsui.prototype.addContentToTab = function(tab_name, content) { - var tab = this.addNewTab(tab_name); - tab.appendText(this.formatMessage(content)); + var tab = null; + + if ($cs.opts.get("enable_msg")) { + tab = this.addNewTab(tab_name); + tab.appendText(this.formatMessage(content)); + } }; Nsui.prototype.formatInteger = function(num, len) { @@ -149,12 +153,4 @@ Nsui.prototype.init = function() { elem.hideAllTabs(); }; })(this); - - if (typeof $cs.client !== "undefined") { - NsClient.prototype.msgHandler = (function(elem) { - return function(msg) { - elem.addContentToTab(msg.login, msg); - }; - })(this); - } }; diff --git a/lib/tab.nsui.js b/lib/tab.nsui.js index d2de41a..1576274 100644 --- a/lib/tab.nsui.js +++ b/lib/tab.nsui.js @@ -77,7 +77,7 @@ Tab.prototype.initBodyElement = function() { var msg = this.value; this.value = ""; - if (typeof $cs.client !== "undefined") { + if (typeof $cs.client !== "undefined" && $cs.opts.get("enable_msg")) { $cs.client.sendMessage(elem.name, msg); $cs.ui.addContentToTab(elem.name, {"message": msg}); } else {