From a22a69f36a7d9c34f6fbd0b6c15a0833fcf0a5f4 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 21 Jan 2013 18:31:51 +0000 Subject: [PATCH] Callback fix on on truncated messages --- server/clientcommands.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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); }); }, -- 2.25.1