Add support for MONITOR
This commit is contained in:
@@ -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] });
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -42,6 +42,12 @@ export const ERR_UNAVAILRESOURCE = "437";
|
||||
// Other
|
||||
export const RPL_QUIETLIST = "728";
|
||||
export const RPL_ENDOFQUIETLIST = "729";
|
||||
// IRCv3 MONITOR: https://ircv3.net/specs/extensions/monitor
|
||||
export const RPL_MONONLINE = "730";
|
||||
export const RPL_MONOFFLINE = "731";
|
||||
export const RPL_MONLIST = "732";
|
||||
export const RPL_ENDOFMONLIST = "733";
|
||||
export const ERR_MONLISTFULL = "734";
|
||||
// IRCv3 SASL: https://ircv3.net/specs/extensions/sasl-3.1
|
||||
export const RPL_LOGGEDIN = "900";
|
||||
export const RPL_LOGGEDOUT = "901";
|
||||
@@ -107,7 +113,7 @@ export function formatTags(tags) {
|
||||
return l.join(";");
|
||||
}
|
||||
|
||||
function parsePrefix(s) {
|
||||
export function parsePrefix(s) {
|
||||
let prefix = {
|
||||
name: null,
|
||||
user: null,
|
||||
@@ -306,6 +312,7 @@ export function isError(cmd) {
|
||||
case ERR_SASLTOOLONG:
|
||||
case ERR_SASLABORTED:
|
||||
case ERR_SASLALREADY:
|
||||
case ERR_MONLISTFULL:
|
||||
return true;
|
||||
case "FAIL":
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user