# HG changeset patch # User Ascrod <32915892+Ascrod@users.noreply.github.com> # Date 1592172744 14400 # Parent 36cd8043019e6d7810082bf8de8401773e12a31b Bug 1717369 - Make line splitting a library utility function in cZ. r=IanN a=IanN Make line splitting a library utility function. Fix sending CTCP commands without message content. diff --git a/suite/extensions/irc/js/lib/irc.js b/suite/extensions/irc/js/lib/irc.js --- a/suite/extensions/irc/js/lib/irc.js +++ b/suite/extensions/irc/js/lib/irc.js @@ -852,55 +852,74 @@ CIRCServer.prototype.queuedSendData = function serv_senddata (msg) { if (this.sendQueue.length == 0) this.parent.eventPump.addEvent (new CEvent ("server", "senddata", this, "onSendData")); arrayInsertAt (this.sendQueue, 0, new String(msg)); } -CIRCServer.prototype.messageTo = -function serv_messto (code, target, msg, ctcpCode) +// Utility method for splitting large lines prior to sending. +CIRCServer.prototype.splitLinesForSending = +function serv_splitlines(line, prettyWrap) { - var lines = String(msg).split ("\n"); - var i = 0; - var pfx = "", sfx = ""; - - if (ctcpCode) - { - pfx = "\01" + ctcpCode; - sfx = "\01"; - } - - for (i in lines) + let lines = String(line).split("\n"); + let realLines = []; + for (let i = 0; i < lines.length; i++) { if (lines[i]) { while (lines[i].length > this.maxLineLength) { var extraLine = lines[i].substr(0, this.maxLineLength - 5); var pos = extraLine.lastIndexOf(" "); if ((pos >= 0) && (pos >= this.maxLineLength - 15)) { // Smart-split. - extraLine = lines[i].substr(0, pos) + "..."; - lines[i] = "..." + lines[i].substr(extraLine.length - 2); + extraLine = lines[i].substr(0, pos); + lines[i] = lines[i].substr(extraLine.length + 1); + if (prettyWrap) + { + extraLine += "..."; + lines[i] = "..." + lines[i]; + } } else { - // Dump-split. + // Dumb-split. extraLine = lines[i].substr(0, this.maxLineLength); lines[i] = lines[i].substr(extraLine.length); } - if (!this.messageTo(code, target, extraLine, ctcpCode)) - return false; + realLines.push(extraLine); } + realLines.push(lines[i]); } } + return realLines; +} + +CIRCServer.prototype.messageTo = +function serv_messto(code, target, msg, ctcpCode) +{ + let lines = this.splitLinesForSending(msg, true); + + let i = 0; + let pfx = ""; + let sfx = ""; + + if (ctcpCode) + { + pfx = "\01" + ctcpCode; + sfx = "\01"; + } + + // We may have no message at all with CTCP commands. + if (!lines.length && ctcpCode) + lines.push(""); for (i in lines) { if ((lines[i] != "") || ctcpCode) { var line = code + " " + target + " :" + pfx; if (lines[i] != "") { @@ -908,20 +927,17 @@ function serv_messto (code, target, msg, line += " "; line += lines[i] + sfx; } else line += sfx; //dd ("-*- irc sending '" + line + "'"); this.sendData(line + "\n"); } - } - - return true; } CIRCServer.prototype.sayTo = function serv_sayto (target, msg) { this.messageTo("PRIVMSG", target, msg); } diff --git a/suite/extensions/irc/xul/content/commands.js b/suite/extensions/irc/xul/content/commands.js --- a/suite/extensions/irc/xul/content/commands.js +++ b/suite/extensions/irc/xul/content/commands.js @@ -2028,17 +2028,17 @@ function cmdMsg(e) function _sendMsgTo(message, msgType, target, displayObj) { if (!displayObj) displayObj = target; var msg = filterOutput(message, msgType, target); var o = getObjectDetails(target); - var lines = o.server ? o.server.splitLinesForSending(msg) : [msg]; + var lines = o.server ? o.server.splitLinesForSending(msg, true) : [msg]; for (var i = 0; i < lines.length; i++) { msg = lines[i]; client.munger.getRule(".mailto").enabled = client.prefs["munger.mailto"]; displayObj.display(msg, msgType, "ME!", target); client.munger.getRule(".mailto").enabled = false; if (msgType == "PRIVMSG") diff --git a/suite/extensions/irc/xul/content/static.js b/suite/extensions/irc/xul/content/static.js --- a/suite/extensions/irc/xul/content/static.js +++ b/suite/extensions/irc/xul/content/static.js @@ -4092,52 +4092,16 @@ function dccfile_getprefs() } CIRCDCCFileTransfer.prototype.__defineGetter__("prefManager", dccfile_getprefmgr); function dccfile_getprefmgr() { return this.user.prefManager; } -// This is a copy of the splitting done in CIRCServer.prototype.messageTo -// Please keep this in mind when editing: -CIRCServer.prototype.splitLinesForSending = -function my_splitlinesforsending(line) -{ - var lines = line.split("\n"); - var realLines = new Array(); - for (var i = 0; i < lines.length; i++) - { - if (lines[i]) - { - while (lines[i].length > this.maxLineLength) - { - var extraLine = lines[i].substr(0, this.maxLineLength - 5); - var pos = extraLine.lastIndexOf(" "); - - if ((pos >= 0) && (pos >= this.maxLineLength - 15)) - { - // Smart-split. - extraLine = lines[i].substr(0, pos) + "..."; - lines[i] = "..." + lines[i].substr(extraLine.length - 2); - } - else - { - // Dump-split. - extraLine = lines[i].substr(0, this.maxLineLength); - lines[i] = lines[i].substr(extraLine.length); - } - realLines.push(extraLine); - } - realLines.push(lines[i]); - } - } - return realLines; -} - /* Displays a network-centric message on the most appropriate view. * * When |client.SLOPPY_NETWORKS| is |true|, messages will be displayed on the * *current* view instead of the network view, if the current view is part of * the same network. */ CIRCNetwork.prototype.display = function net_display(message, msgtype, sourceObj, destObj)