From: Darren Date: Mon, 21 Jan 2013 18:31:51 +0000 (+0000) Subject: Callback fix on on truncated messages X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a22a69f36a7d9c34f6fbd0b6c15a0833fcf0a5f4;p=KiwiIRC.git Callback fix on on truncated messages --- diff --git a/server/clientcommands.js b/server/clientcommands.js index 4463d8f..b7e8de2 100644 --- a/server/clientcommands.js +++ b/server/clientcommands.js @@ -46,8 +46,13 @@ var listeners = { // be sent from the IRCd to the target without being truncated. var blocks = truncateString(args.msg, 350); - blocks.forEach(function (block) { - irc_connection.write('PRIVMSG ' + args.target + ' :' + block); + blocks.forEach(function (block, idx) { + // Apply the callback on the last message only + var cb = (idx === blocks.length - 1) ? + callback : + undefined; + + irc_connection.write('PRIVMSG ' + args.target + ' :' + block, cb); }); }, @@ -120,8 +125,13 @@ var listeners = { // be sent from the IRCd to the target without being truncated. var blocks = truncateString(args.msg, 350); - blocks.forEach(function (block) { - irc_connection.write('NOTICE ' + args.target + ' :' + block); + blocks.forEach(function (block, idx) { + // Apply the callback on the last message only + var cb = (idx === blocks.length - 1) ? + callback : + undefined; + + irc_connection.write('NOTICE ' + args.target + ' :' + block, cb); }); },