Skip to content

patch nested batches #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/commands/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call me old fashioned, but I like my caches to not change while I'm reading them.

Are you sure this is what you want to do ?

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);
}
Expand Down
11 changes: 8 additions & 3 deletions src/commands/handlers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Expand All @@ -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);
});
Expand Down