Add support for MONITOR
This commit is contained in:
parent
dd67e0789e
commit
e283d9c7ab
4 changed files with 82 additions and 2 deletions
|
@ -54,6 +54,7 @@ export default class Client extends EventTarget {
|
|||
pingIntervalID = null;
|
||||
pendingHistory = Promise.resolve(null);
|
||||
cm = irc.CaseMapping.RFC1459;
|
||||
monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
|
||||
whoisDB = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
|
||||
|
||||
constructor(params) {
|
||||
|
@ -97,6 +98,7 @@ export default class Client extends EventTarget {
|
|||
this.batches = new Map();
|
||||
this.pendingHistory = Promise.resolve(null);
|
||||
this.isupport = new Map();
|
||||
this.monitored = new irc.CaseMapMap(null, irc.CaseMapping.RFC1459);
|
||||
|
||||
if (this.autoReconnect) {
|
||||
if (!navigator.onLine) {
|
||||
|
@ -199,6 +201,10 @@ export default class Client extends EventTarget {
|
|||
if (changed.indexOf("CASEMAPPING") >= 0) {
|
||||
this.setCaseMapping(this.isupport.get("CASEMAPPING"));
|
||||
}
|
||||
if (changed.indexOf("MONITOR") >= 0 && this.isupport.has("MONITOR")) {
|
||||
let targets = Array.from(this.monitored.keys()).slice(0, this.maxMonitorTargets());
|
||||
this.send({ command: "MONITOR", params: ["+", targets.join(",")] });
|
||||
}
|
||||
break;
|
||||
case irc.RPL_ENDOFMOTD:
|
||||
case irc.ERR_NOMOTD:
|
||||
|
@ -478,6 +484,7 @@ export default class Client extends EventTarget {
|
|||
}
|
||||
|
||||
this.whoisDB = new irc.CaseMapMap(this.whoisDB, this.cm);
|
||||
this.monitored = new irc.CaseMapMap(this.monitored, this.cm);
|
||||
}
|
||||
|
||||
isServer(name) {
|
||||
|
@ -683,4 +690,40 @@ export default class Client extends EventTarget {
|
|||
return networks;
|
||||
});
|
||||
}
|
||||
|
||||
maxMonitorTargets() {
|
||||
if (!this.isupport.has("MONITOR")) {
|
||||
return 0;
|
||||
}
|
||||
return parseInt(this.isupport.get("MONITOR"), 10);
|
||||
}
|
||||
|
||||
monitor(target) {
|
||||
if (this.monitored.has(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.monitored.set(target, true);
|
||||
|
||||
// TODO: add poll-based fallback when MONITOR is not supported
|
||||
if (this.monitored.size + 1 > this.maxMonitorTargets()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.send({ command: "MONITOR", params: ["+", target] });
|
||||
}
|
||||
|
||||
unmonitor(target) {
|
||||
if (!this.monitored.has(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.monitored.delete(target);
|
||||
|
||||
if (!this.isupport.has("MONITOR")) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.send({ command: "MONITOR", params: ["-", target] });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue