Add Client.join, show join errors in popup

This commit is contained in:
Simon Ser 2021-12-04 17:44:23 +01:00
parent fc8aa30756
commit 05f7c6e9fe
3 changed files with 36 additions and 2 deletions

View file

@ -318,7 +318,7 @@ export default class App extends Component {
} }
showError(msg) { showError(msg) {
this.setState({ error: msg }); this.setState({ error: String(msg) });
lastErrorID++; lastErrorID++;
return lastErrorID; return lastErrorID;
} }
@ -1119,7 +1119,9 @@ export default class App extends Component {
this.switchBuffer({ server: serverID }); this.switchBuffer({ server: serverID });
} else if (client.isChannel(target)) { } else if (client.isChannel(target)) {
this.switchToChannel = target; this.switchToChannel = target;
client.send({ command: "JOIN", params: [target] }); client.join(target).catch((err) => {
this.showError(err);
});
} else { } else {
this.whoUserBuffer(target, serverID); this.whoUserBuffer(target, serverID);
this.createBuffer(serverID, target); this.createBuffer(serverID, target);

View file

@ -789,6 +789,32 @@ export default class Client extends EventTarget {
}); });
} }
join(channel) {
let msg = {
command: "JOIN",
params: [channel],
};
return this.roundtrip(msg, (msg) => {
switch (msg.command) {
case irc.ERR_NOSUCHCHANNEL:
case irc.ERR_TOOMANYCHANNELS:
case irc.ERR_BADCHANNELKEY:
case irc.ERR_BANNEDFROMCHAN:
case irc.ERR_CHANNELISFULL:
case irc.ERR_INVITEONLYCHAN:
if (this.cm(msg.params[1]) === this.cm(channel)) {
throw new IRCError(msg);
}
break;
case "JOIN":
if (this.isMyNick(msg.prefix.name) && this.cm(msg.params[0]) === this.cm(channel)) {
return true;
}
break;
}
});
}
fetchBatch(msg, batchType) { fetchBatch(msg, batchType) {
let batchName = null; let batchName = null;
let messages = []; let messages = [];

View file

@ -34,6 +34,8 @@ export const RPL_MOTDSTART = "375";
export const RPL_ENDOFMOTD = "376"; export const RPL_ENDOFMOTD = "376";
export const ERR_UNKNOWNERROR = "400"; export const ERR_UNKNOWNERROR = "400";
export const ERR_NOSUCHNICK = "401"; export const ERR_NOSUCHNICK = "401";
export const ERR_NOSUCHCHANNEL = "403";
export const ERR_TOOMANYCHANNELS = "405";
export const ERR_UNKNOWNCOMMAND = "421"; export const ERR_UNKNOWNCOMMAND = "421";
export const ERR_NOMOTD = "422"; export const ERR_NOMOTD = "422";
export const ERR_ERRONEUSNICKNAME = "432"; export const ERR_ERRONEUSNICKNAME = "432";
@ -43,6 +45,10 @@ export const ERR_NEEDMOREPARAMS = "461";
export const ERR_NOPERMFORHOST = "463"; export const ERR_NOPERMFORHOST = "463";
export const ERR_PASSWDMISMATCH = "464"; export const ERR_PASSWDMISMATCH = "464";
export const ERR_YOUREBANNEDCREEP = "465"; export const ERR_YOUREBANNEDCREEP = "465";
export const ERR_CHANNELISFULL = "471";
export const ERR_INVITEONLYCHAN = "473";
export const ERR_BANNEDFROMCHAN = "474";
export const ERR_BADCHANNELKEY = "475";
// RFC 2812 // RFC 2812
export const ERR_UNAVAILRESOURCE = "437"; export const ERR_UNAVAILRESOURCE = "437";
// Other // Other