Only allow one WHO command at a time

Closes: https://todo.sr.ht/~emersion/gamja/120
This commit is contained in:
Simon Ser 2021-11-10 10:08:47 +01:00
parent 195e4ca371
commit c11bf6508a

View File

@ -77,7 +77,10 @@ export default class Client extends EventTarget {
autoReconnect = true;
reconnectTimeoutID = null;
pingIntervalID = null;
pendingHistory = Promise.resolve(null);
pendingCmds = {
WHO: Promise.resolve(null),
CHATHISTORY: Promise.resolve(null),
};
cm = irc.CaseMapping.RFC1459;
monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
pendingLists = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
@ -126,7 +129,9 @@ export default class Client extends EventTarget {
this.availableCaps = {};
this.enabledCaps = {};
this.batches = new Map();
this.pendingHistory = Promise.resolve(null);
Object.keys(this.pendingCmds).forEach((k) => {
this.pendingCmds[k] = Promise.resolve(null);
});
this.isupport = new Map();
this.monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
@ -394,27 +399,30 @@ export default class Client extends EventTarget {
let msg = { command: "WHO", params };
let l = [];
return this.roundtrip(msg, (msg) => {
switch (msg.command) {
case irc.RPL_WHOREPLY:
// TODO: match with mask
l.push(this.parseWhoReply(msg));
break;
case irc.RPL_WHOSPCRPL:
if (msg.params.length !== fields.length || msg.params[1] !== token) {
let promise = this.pendingCmds.WHO.then(() => {
return this.roundtrip(msg, (msg) => {
switch (msg.command) {
case irc.RPL_WHOREPLY:
l.push(this.parseWhoReply(msg));
break;
case irc.RPL_WHOSPCRPL:
if (msg.params.length !== fields.length || msg.params[1] !== token) {
break;
}
l.push(this.parseWhoReply(msg));
break;
case irc.RPL_ENDOFWHO:
if (msg.params[1] === mask) {
return l;
}
break;
}
l.push(this.parseWhoReply(msg));
break;
case irc.RPL_ENDOFWHO:
if (msg.params[1] === mask) {
return l;
}
break;
}
}).finally(() => {
this.whoxQueries.delete(token);
}).finally(() => {
this.whoxQueries.delete(token);
});
});
this.pendingCmds.WHO = promise.catch(() => {});
return promise;
}
parseWhoReply(msg) {
@ -741,14 +749,15 @@ export default class Client extends EventTarget {
roundtripChatHistory(params) {
// Don't send multiple CHATHISTORY commands in parallel, we can't
// properly handle batches and errors.
this.pendingHistory = this.pendingHistory.catch(() => {}).then(() => {
let promise = this.pendingCmds.CHATHISTORY.then(() => {
let msg = {
command: "CHATHISTORY",
params,
};
return this.fetchBatch(msg, "chathistory").then((batch) => batch.messages);
});
return this.pendingHistory;
this.pendingCmds.CHATHISTORY = promise.catch(() => {});
return promise;
}
chatHistoryPageSize() {