lib/client: extract fetchBatch function from roundtripChatHistory

This commit is contained in:
Simon Ser 2021-03-03 14:13:05 +01:00
parent 3ece5f1ca5
commit aa79067179

View File

@ -370,14 +370,7 @@ 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(() => {
var msg = {
command: "CHATHISTORY",
params,
};
fetchBatch(msg, batchType) {
return this.roundtrip(msg, (event) => {
var msg = event.detail.message;
@ -389,17 +382,28 @@ export default class Client extends EventTarget {
break;
}
var batch = this.batches.get(name);
if (batch.type == "chathistory") {
if (batch.type === batchType) {
return batch;
}
break;
case "FAIL":
if (msg.params[0] == "CHATHISTORY") {
if (msg.params[0] === msg.command) {
throw msg;
}
break;
}
});
}
roundtripChatHistory(params) {
// Don't send multiple CHATHISTORY commands in parallel, we can't
// properly handle batches and errors.
this.pendingHistory = this.pendingHistory.catch(() => {}).then(() => {
var msg = {
command: "CHATHISTORY",
params,
};
return this.fetchBatch(msg, "chathistory");
});
return this.pendingHistory;
}