diff --git a/src/commands/handler.js b/src/commands/handler.js index 2cb46aff..f3f0f84d 100644 --- a/src/commands/handler.js +++ b/src/commands/handler.js @@ -41,13 +41,21 @@ module.exports = class IrcCommandHandler extends EventEmitter { if (batch_id) { const cache_key = 'batch.' + batch_id; if (this.hasCache(cache_key)) { - const cache = this.cache(cache_key); + let cache = this.cache(cache_key); cache.commands.push(irc_command); + while (cache?.tags?.batch) { + cache = this.cache('batch.' + cache.tags.batch); + cache.commands.push(irc_command); + } } else { // If we don't have this batch ID in cache, it either means that the // server hasn't sent the starting batch command or that the server // has already sent the end batch command. } + // start interleaving batches anyway + if (irc_command.command === 'BATCH' && irc_command.params[0].charAt(0) === '+') { + this.executeCommand(irc_command); + } } else { this.executeCommand(irc_command); } diff --git a/src/commands/handlers/misc.js b/src/commands/handlers/misc.js index 2fcef18a..dd9c8645 100644 --- a/src/commands/handlers/misc.js +++ b/src/commands/handlers/misc.js @@ -310,11 +310,13 @@ const handlers = { } if (batch_start) { + // in case of an interleaving batch + if (handler.hasCache(cache_key)) return; const cache = handler.cache(cache_key); cache.commands = []; cache.type = command.params[1]; cache.params = command.params.slice(2); - + cache.tags = command.tags; return; } @@ -330,7 +332,8 @@ const handlers = { id: batch_id, type: cache.type, params: cache.params, - commands: cache.commands + commands: cache.commands, + tags: cache.tags, }; // Destroy the cache object before executing each command. If one @@ -340,10 +343,12 @@ const handlers = { handler.emit('batch start', emit_obj); handler.emit('batch start ' + emit_obj.type, emit_obj); emit_obj.commands.forEach((c) => { + if (c.getTag('batch') !== batch_id) return; c.batch = { id: batch_id, type: cache.type, - params: cache.params + params: cache.params, + tags: cache.tags, }; handler.executeCommand(c); });