* irc.js
add ctcpTo(), ctcp() methods
forward unknown ctcp codes to onUnknownCTCP handler

* utils.js
add abbreviateWord function

* commands.js
add /ctcp command

* handler.js
make |this| refer to client.currentObject in /eval
implement /ctcp command
chop long hostnames onJoin
add onUnknownCTCP handler
redraw fixes in on366, onPart

* rdf.js
add getTreeRoot method

* static.js
comment fixes
add max word/nick display vars, implementations
updateTitle changes, show correct title based on client.currentObject
fix delete view issue
chop long nicks before displaying
This commit is contained in:
rginda%netscape.com 2000-05-15 05:58:30 +00:00
Родитель 14ec9d6de0
Коммит 6a0a36b5f8
7 изменённых файлов: 257 добавлений и 91 удалений

Просмотреть файл

@ -337,7 +337,7 @@ function serv_messto (code, target, msg, ctcpCode)
}
for (i in lines)
if (lines[i] != "") sendable++;
if ((lines[i] != "") || ctcpCode) sendable++;
for (i in lines)
{
@ -351,17 +351,17 @@ function serv_messto (code, target, msg, ctcpCode)
return true;
}
if (lines[i] != "")
if ((lines[i] != "") || ctcpCode)
{
this.sendsThisRound++;
this.sendData (code + " " + target + " :" + pfx + lines[i] +
sfx + "\n");
var line = code + " " + target + " :" + pfx + lines[i] + sfx;
//dd ("-*- irc sending '" + line + "'");
this.sendData (line + "\n");
}
}
return true;
return true;
}
CIRCServer.prototype.sayTo =
@ -387,6 +387,21 @@ function serv_actto (target, msg)
this.messageTo ("PRIVMSG", target, msg, "ACTION");
}
CIRCServer.prototype.ctcpTo =
function serv_ctcpto (target, code, msg, method)
{
if (typeof msg == "undefined")
msg = "";
if (typeof method == "undefined")
method = "PRIVMSG";
this.messageTo (method, target, msg, code);
}
/**
* Abstracts the whois command.
*
@ -1175,8 +1190,9 @@ function serv_ctcp (e)
return false;
e.CTCPData = ary[2] ? ary[2] : "";
e.type = "ctcp-" + ary[1].toLowerCase();
e.CTCPCode = ary[1].toLowerCase();
e.type = "ctcp-" + e.CTCPCode;
e.destMethod = "onCTCP" + ary[1][0].toUpperCase() +
ary[1].substr (1, ary[1].length).toLowerCase();
@ -1184,6 +1200,12 @@ function serv_ctcp (e)
{ /* if there's no place to land the event here, try to forward it */
e.destObject = e.replyTo;
e.set = (e.replyTo == e.user) ? "user" : "channel";
if (typeof e.replyTo[e.destMethod] != "function")
{ /* if there's no place to forward it, send it to unknownCTCP */
e.type = "unk-ctcp";
e.destMethod = "onUnknownCTCP";
}
}
else
e.destObject = this;
@ -1382,6 +1404,20 @@ function chan_notice (msg)
}
CIRCChannel.prototype.ctcp =
function chan_ctcpto (code, msg, type)
{
if (typeof msg == "undefined")
msg = "";
if (typeof type == "undefined")
type = "PRIVMSG";
this.parent.messageTo (type, this.name, msg, code);
}
CIRCChannel.prototype.join =
function chan_join ()
{
@ -1668,6 +1704,20 @@ function usr_act (msg)
}
CIRCUser.prototype.ctcp =
function usr_ctcp (code, msg, type)
{
if (typeof msg == "undefined")
msg = "";
if (typeof type == "undefined")
type = "PRIVMSG";
this.parent.messageTo (type, this.name, msg, code);
}
CIRCUser.prototype.whois =
function usr_whois ()
{

Просмотреть файл

@ -384,6 +384,18 @@ function arrayRemoveAt (ary, i)
}
/* length should be an even number >= 6 */
function abbreviateWord (str, length)
{
if (str.length <= length || length < 6)
return str;
var left = str.substr (0, (length / 2) - 1);
var right = str.substr (str.length - (length / 2) + 1);
return left + "..." + right;
}
function getRandomElement (ary)
{
var i = parseInt (Math.random() * ary.length)

Просмотреть файл

@ -139,7 +139,7 @@
<box id="outer-box" align="vertical" flex="1">
<box id="inner-box" align="horizontal" flex="1">
<box id="user-list-box" flex="40%">
<box id="user-list-box" flex="30%">
<tree id="user-list" container="true" datasources="rdf:null" flex="1"
containment="http://home.netscape.com/NC-irc#chanuser">

Просмотреть файл

@ -125,6 +125,11 @@ function addCommands(commandObject)
"<script>",
"Evaluates <script> as JavaScript code. Not for the faint of heart.");
add ("ctcp", "onInputCTCP",
"<target> <code> [<params>]",
"Sends the CTCP code <code> to the target (user or channel) " +
"<target>. If <params> are specified they are sent along as well.");
add ("join", "onInputJoin",
"[#|&]<channel-name>",
"Joins a the global (name starts with #) or local (name starts " +

Просмотреть файл

@ -156,6 +156,8 @@ function onToggleVisibility(thing)
elem.setAttribute ("collapsed", newState);
}
updateTitle();
}
function onDoStyleChange (newStyle)
@ -178,21 +180,17 @@ function onHideCurrentView()
var tb = getTBForObject(client.currentObject);
if (tb)
if (deleteToolbutton (tb))
setCurrentObject (client);
}
function onClearCurrentView()
{
if (client.output.firstChild)
client.output.removeChild (client.output.firstChild);
delete client.currentObject.messages;
client.currentObject.display ("Messages Cleared.", "INFO");
client.output.appendChild (client.currentObject.messages);
{
var i = deleteToolbutton (tb);
if (i != -1)
{
if (i >= client.viewsArray.length)
i = client.viewsArray.length - 1;
setCurrentObject (client.viewsArray[i].source);
}
}
}
@ -202,20 +200,37 @@ function onDeleteCurrentView()
if (tb)
{
if (deleteToolbutton (tb))
var i = deleteToolbutton (tb);
if (i != -1)
{
delete client.currentObject.messages;
setCurrentObject (client);
if (i >= client.viewsArray.length)
i = client.viewsArray.length - 1;
setCurrentObject (client.viewsArray[i].source);
}
}
}
function onClearCurrentView()
{
if (client.output.firstChild)
client.output.removeChild (client.output.firstChild);
client.currentObject.messages = (void 0);
delete client.currentObject.messages;
client.currentObject.display ("Messages Cleared.", "INFO");
client.output.appendChild (client.currentObject.messages);
}
function onSortCol(sortColName)
{
dd ("in sortcol");
const nsIXULSortService = Components.interfaces.nsIXULSortService;
const isupports_uri = "component://netscape/rdf/xul-sort-service";
@ -978,7 +993,9 @@ function cli_ieval (e)
try
{
rv = String(eval (e.inputData));
client.currentObject.doEval = function (s) { return eval(s); }
rv = String(client.currentObject.doEval (e.inputData));
if (rv.indexOf ("\n") == -1)
client.currentObject.display ("{" + e.inputData + "} " + rv,
"EVAL");
@ -994,7 +1011,31 @@ function cli_ieval (e)
return true;
}
client.onInputCTCP =
function cli_ictcp (e)
{
if (!e.inputData)
return false;
if (!e.server)
{
client.currentObject.display ("You must be connected to a server to " +
"use CTCP.", "ERROR");
return false;
}
var ary = e.inputData.match(/^(\S+) (\S+)$/);
if (ary == null)
return false;
e.server.ctcpTo (ary[1], ary[2]);
return true;
}
client.onInputJoin =
function cli_ijoin (e)
{
@ -1649,6 +1690,10 @@ CIRCChannel.prototype.on366 =
function my_366 (e)
{
if (client.currentObject == this)
/* hide the tree while we add (possibly tons) of nodes */
client.rdf.setTreeRoot("user-list", client.rdf.resNullChan);
client.rdf.clearTargets(this.getGraphResource(), client.rdf.resChanUser);
for (var u in this.users)
@ -1656,6 +1701,11 @@ function my_366 (e)
this.users[u].updateGraphResource();
this._addUserToGraph (this.users[u]);
}
if (client.currentObject == this)
/* redisplay the tree */
client.rdf.setTreeRoot("user-list", this.getGraphResource());
}
@ -1690,6 +1740,15 @@ function my_caction (e)
}
CIRCChannel.prototype.onUnknownCTCP =
function my_unkctcp (e)
{
this.display ("Unknown CTCP " + e.CTCPCode + "(" + e.CTCPData +
") from " + e.user.properNick, "BAD-CTCP");
}
CIRCChannel.prototype.onJoin =
function my_cjoin (e)
{
@ -1701,8 +1760,8 @@ function my_cjoin (e)
}
else
this.display(e.user.properNick + " (" + e.user.name + "@" +
e.user.host + ") has joined " + e.channel.name,
"JOIN", e.user.nick);
abbreviateWord(e.user.host, client.MAX_WORD_DISPLAY) +
") has joined " + e.channel.name, "JOIN", e.user.nick);
this._addUserToGraph (e.user);
@ -1719,8 +1778,16 @@ function my_cpart (e)
if (userIsMe (e.user))
{
this.display ("YOU have left " + e.channel.name, "PART", "!ME");
if (client.currentObject == this)
/* hide the tree while we remove (possibly tons) of nodes */
client.rdf.setTreeRoot("user-list", client.rdf.resNullChan);
client.rdf.clearTargets(this.getGraphResource(),
client.rdf.resChanUser, true);
if (client.currentObject == this)
/* redisplay the tree */
client.rdf.setTreeRoot("user-list", this.getGraphResource());
}
else
this.display (e.user.properNick + " has left " + e.channel.name,
@ -1758,7 +1825,7 @@ function my_ckick (e)
e.reason + ")", "KICK", enforcerNick);
}
this._removeUserFromGraph(e.user);
this._removeUserFromGraph(e.lamer);
updateChannel (e.channel);
@ -1851,3 +1918,12 @@ function my_notice (e)
}
CIRCUser.prototype.onUnknownCTCP =
function my_unkctcp (e)
{
this.parent.parent.display ("Unknown CTCP " + e.CTCPCode + "(" +
e.CTCPData + ") from " + e.user.properNick,
"BAD-CTCP");
}

Просмотреть файл

@ -176,8 +176,10 @@ function rdf_inittree (n1, a, recurse)
}
catch (e)
{
/*
dd ("** Caught " + e + " while recursivley clearing " +
n2.Value + " **");
*/
}
}
@ -202,3 +204,11 @@ function rdf_settroot (id, root)
root = root.Value;
tree.setAttribute ("ref", root);
}
RDFHelper.prototype.getTreeRoot =
function rdf_gettroot (id, root)
{
var tree = document.getElementById (id);
return tree.getAttribute ("ref");
}

Просмотреть файл

@ -10,16 +10,13 @@
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is JSIRC Test Client #3
* The Original Code is ChatZilla
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
@ -30,16 +27,19 @@ client.defaultNick = "IRCMonkey";
client.IMAGEDIR = "chrome://chatzilla/skin/images/";
client.CSSDIR = "chrome://chatzilla/skin/";
//client.IMAGEDIR = "resource:///chrome/chatzilla/skin/default/images/";
//client.CSSDIR = "resource:///chrome/chatzilla/skin/default/";
client.COMMAND_CHAR = "/";
client.STEP_TIMEOUT = 500;
client.UPDATE_DELAY = 500;
//client.UPDATE_DELAY = 500;
client.EXPAND_HEIGHT = "200px";
client.COLLAPSE_HEIGHT = "25px";
client.MAX_MESSAGES = 200;
client.MAX_HISTORY = 50;
/* longest nick to show in display before abbreviating */
client.MAX_NICK_DISPLAY = 14;
/* longest word to show in display before abbreviating, currently
* only for urls and hostnames onJoin */
client.MAX_WORD_DISPLAY = 46;
client.TYPE = "IRCClient";
client.PRINT_DIRECTION = 1; /*1 => new messages at bottom, -1 => at top */
client.ADDRESSED_NICK_SEP = ", ";
@ -121,7 +121,8 @@ function initStatic()
setMenuCheck ("menu-view-info", isVisible("user-list"));
client.uiState["status"] =
setMenuCheck ("menu-view-status", isVisible("status-bar-tbox"));
onSortCol ("usercol-nick");
}
function setMenuCheck (id, state)
@ -239,6 +240,8 @@ function insertLink (matchText, containerTag)
var anchor = document.createElement ("html:a");
anchor.setAttribute ("href", href);
anchor.setAttribute ("target", "other_window");
if (matchText.length >= client.MAX_WORD_DISPLAY)
matchText = abbreviateWord (matchText, client.MAX_WORD_DISPLAY);
anchor.appendChild (document.createTextNode (matchText));
containerTag.appendChild (anchor);
@ -391,7 +394,7 @@ function setClientOutput(doc)
client.output = doc.getElementById("output");
/* continue processing now: */
initStatic();
if (0 && client.STARTUP_NETWORK)
if (client.STARTUP_NETWORK)
client.onInputAttach ({inputData: client.STARTUP_NETWORK});
}
@ -477,43 +480,52 @@ function updateTitle (obj)
getObjectDetails (client.currentObject, o);
var net = o.network ? o.network.name : "";
var serv = "", nick = "";
if (o.server)
switch (client.currentObject.TYPE)
{
serv = o.server.connection.host;
if (o.server.me)
case "IRCServer":
case "IRCNetwork":
var serv = "", nick = "";
serv = o.server.connection.host;
nick = o.server.me.properNick;
}
if (o.channel)
{
var chan = "(none)", mode = "", topic = "";
chan = o.channel.name;
mode = o.channel.mode.getModeStr();
if (client.uiState["toolbar"])
topic = o.channel.topic ? " " + o.channel.topic : " --no topic--";
if (!mode)
mode = "no mode";
tstring = chan + " (" + mode + ") " + topic;
}
else
{
if (nick)
tstring += "user '" + nick + "' ";
if (net)
if (serv)
tstring += "attached to '" + net + "' via " + serv;
if (nick) /* user might be disconnected, nick would be undefined */
tstring += "user '" + nick + "' ";
if (net)
if (serv)
tstring += "attached to '" + net + "' via " + serv;
else
tstring += "attaching to '" + net + "'";
if (tstring)
tstring = "ChatZilla: " + tstring;
else
tstring += "attaching to '" + net + "'";
if (tstring)
tstring = "ChatZilla: " + tstring;
else
tstring = "ChatZilla!!";
break;
case "IRCChannel":
var chan = "(none)", mode = "", topic = "";
chan = o.channel.name;
mode = o.channel.mode.getModeStr();
if (client.uiState["toolbar"])
topic = o.channel.topic ? " " + o.channel.topic :
" --no topic--";
if (!mode)
mode = "no mode";
tstring = "ChatZilla: " + chan + " (" + mode + ") " + topic;
break;
case "IRCUser":
tstring = "ChatZilla: Conversation with " +
client.currentObject.properNick;
break;
default:
tstring = "ChatZilla!";
break;
}
if (!client.uiState["toolbar"])
@ -762,19 +774,20 @@ function getTBForObject (source, create)
for (var i in client.viewsArray)
{
if (client.viewsArray[i].source == source)
{
tb = client.viewsArray[i].tb;
break;
}
else
if (client.viewsArray[i].tb.id == id)
if (client.viewsArray[i].tb.getAttribute("id") == id)
id = "tb[" + name + "<" + (++matches) + ">]";
}
if (!tb && create) /* not found, create one */
{
var views = document.getElementById ("views-tbar-inner");
//var tbi = document.createElement ("toolbaritem");
//tbi.setAttribute ("onclick", "onTBIClick('" + id + "')");
tb = document.createElement ("menubutton");
tb.addEventListener("click", onTBIClickTempHandler, false);
tb.addEventListener("click", onTBIClickTempHandler, false);
var aclass = (client.ICONS_IN_TOOLBAR) ?
"activity-button-image" : "activity-button-text";
@ -790,7 +803,6 @@ function getTBForObject (source, create)
else
tb.setAttribute ("value", name);
//tbi.appendChild (tb);
views.appendChild (tb);
}
@ -822,11 +834,10 @@ function deleteToolbutton (tb)
if (!client.viewsArray[key].source.isPermanent)
{
/* re-index higher toolbuttons */
for (i = key + 1; i < client.viewsArray.length; i--)
for (i = key + 1; i < client.viewsArray.length; i++)
{
tb.setAttribute ("viewKey", Number(key) - 1);
client.viewsArray[i].tb.setAttribute ("viewKey", i - 1);
}
arrayRemoveAt(client.viewsArray, key);
var tbinner = document.getElementById("views-tbar-inner");
tbinner.removeChild(tb);
@ -834,7 +845,7 @@ function deleteToolbutton (tb)
else
{
window.alert ("Current view cannot be deleted.");
return false;
return -1;
}
}
@ -842,7 +853,7 @@ function deleteToolbutton (tb)
dd ("*** INVALID OBJECT passed to deleteToolButton (" + tb + ") " +
"no viewKey attribute. (" + key + ")");
return true;
return key;
}
@ -972,22 +983,24 @@ function user_display(message, msgtype, sourceNick)
var nickText;
var realNick = (!sourceNick || sourceNick != "!ME") ? this.properNick :
this.parent.me.properNick;
var displayNick = abbreviateWord (realNick, client.MAX_NICK_DISPLAY);
switch (msgtype)
{
case "ACTION":
nickText = newInlineText ("*" + realNick + "* ",
nickText = newInlineText ("*" + displayNick + "* ",
"msg-user", "html:td");
break;
case "NOTICE":
nickText = newInlineText ("[" + realNick + "] ",
nickText = newInlineText ("[" + displayNick + "] ",
"msg-user", "html:td");
break;
case "PRIVMSG":
nickText = newInlineText (/*"<" +*/ realNick /*+ ">"*/,
nickText = newInlineText (/*"<" +*/ displayNick /*+ ">"*/,
"msg-user", "html:td");
break;
@ -1049,9 +1062,7 @@ function user_display(message, msgtype, sourceNick)
}
else
{
this.parent.display (message, msgtype, this.nick);
}
}
@ -1119,21 +1130,23 @@ function chan_display (message, msgtype, nick)
else
realNick = nick + "?";
var displayNick = abbreviateWord (realNick, client.MAX_NICK_DISPLAY);
switch (msgtype)
{
case "ACTION":
nickText = newInlineText ("*" + realNick + "* ",
nickText = newInlineText ("*" + displayNick + "* ",
"msg-user", "html:td");
break;
case "NOTICE":
nickText = newInlineText ("[" + realNick + "] ",
nickText = newInlineText ("[" + displayNick + "] ",
"msg-user", "html:td");
break;
case "PRIVMSG":
nickText = newInlineText (/*"<" + */ realNick /*+ "> "*/,
nickText = newInlineText (/*"<" + */ displayNick /*+ "> "*/,
"msg-user", "html:td");
break;