forked from CringeStudios/gamja
lib/client: extract fetchBatch function from roundtripChatHistory
This commit is contained in:
parent
3ece5f1ca5
commit
aa79067179
@ -370,14 +370,7 @@ export default class Client extends EventTarget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
roundtripChatHistory(params) {
|
fetchBatch(msg, batchType) {
|
||||||
// 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.roundtrip(msg, (event) => {
|
return this.roundtrip(msg, (event) => {
|
||||||
var msg = event.detail.message;
|
var msg = event.detail.message;
|
||||||
|
|
||||||
@ -389,17 +382,28 @@ export default class Client extends EventTarget {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var batch = this.batches.get(name);
|
var batch = this.batches.get(name);
|
||||||
if (batch.type == "chathistory") {
|
if (batch.type === batchType) {
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "FAIL":
|
case "FAIL":
|
||||||
if (msg.params[0] == "CHATHISTORY") {
|
if (msg.params[0] === msg.command) {
|
||||||
throw msg;
|
throw msg;
|
||||||
}
|
}
|
||||||
break;
|
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;
|
return this.pendingHistory;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user