Implement chathistory support
This commit is contained in:
parent
8809fdcd6a
commit
c9b07efc9c
4 changed files with 136 additions and 16 deletions
|
@ -2,7 +2,15 @@ import * as irc from "./irc.js";
|
|||
|
||||
// Static list of capabilities that are always requested when supported by the
|
||||
// server
|
||||
const permanentCaps = ["message-tags", "server-time", "multi-prefix", "away-notify", "echo-message"];
|
||||
const permanentCaps = [
|
||||
"away-notify",
|
||||
"batch",
|
||||
"draft/chathistory",
|
||||
"echo-message",
|
||||
"message-tags",
|
||||
"multi-prefix",
|
||||
"server-time",
|
||||
];
|
||||
|
||||
export default class Client extends EventTarget {
|
||||
ws = null;
|
||||
|
@ -18,6 +26,7 @@ export default class Client extends EventTarget {
|
|||
registered = false;
|
||||
availableCaps = {};
|
||||
enabledCaps = {};
|
||||
batches = new Map();
|
||||
|
||||
constructor(params) {
|
||||
super();
|
||||
|
@ -65,6 +74,15 @@ export default class Client extends EventTarget {
|
|||
var msg = irc.parseMessage(event.data);
|
||||
console.log("Received:", msg);
|
||||
|
||||
var msgBatch = null;
|
||||
if (msg.tags["batch"]) {
|
||||
msgBatch = this.batches.get(msg.tags["batch"]);
|
||||
if (msgBatch) {
|
||||
msgBatch.messages.push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
var deleteBatch = null;
|
||||
switch (msg.command) {
|
||||
case irc.RPL_WELCOME:
|
||||
if (this.params.saslPlain && this.availableCaps["sasl"] === undefined) {
|
||||
|
@ -115,11 +133,33 @@ export default class Client extends EventTarget {
|
|||
this.nick = newNick;
|
||||
}
|
||||
break;
|
||||
case "BATCH":
|
||||
var enter = msg.params[0].startsWith("+");
|
||||
var name = msg.params[0].slice(1);
|
||||
if (enter) {
|
||||
var batch = {
|
||||
name,
|
||||
type: msg.params[1],
|
||||
params: msg.params.slice(2),
|
||||
parent: msgBatch,
|
||||
messages: [],
|
||||
};
|
||||
this.batches.set(name, batch);
|
||||
} else {
|
||||
deleteBatch = name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
this.dispatchEvent(new CustomEvent("message", {
|
||||
detail: { message: msg },
|
||||
detail: { message: msg, batch: msgBatch },
|
||||
}));
|
||||
|
||||
// Delete after firing the message event so that handlers can access
|
||||
// the batch
|
||||
if (deleteBatch) {
|
||||
this.batches.delete(name);
|
||||
}
|
||||
}
|
||||
|
||||
addAvailableCaps(s) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue