diff --git a/components/app.js b/components/app.js index 9d665e5..5451bf3 100644 --- a/components/app.js +++ b/components/app.js @@ -318,7 +318,7 @@ export default class App extends Component { } showError(msg) { - this.setState({ error: msg }); + this.setState({ error: String(msg) }); lastErrorID++; return lastErrorID; } @@ -1119,7 +1119,9 @@ export default class App extends Component { this.switchBuffer({ server: serverID }); } else if (client.isChannel(target)) { this.switchToChannel = target; - client.send({ command: "JOIN", params: [target] }); + client.join(target).catch((err) => { + this.showError(err); + }); } else { this.whoUserBuffer(target, serverID); this.createBuffer(serverID, target); diff --git a/lib/client.js b/lib/client.js index c5c6652..9f53752 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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) { let batchName = null; let messages = []; diff --git a/lib/irc.js b/lib/irc.js index db130d5..39f204f 100644 --- a/lib/irc.js +++ b/lib/irc.js @@ -34,6 +34,8 @@ export const RPL_MOTDSTART = "375"; export const RPL_ENDOFMOTD = "376"; export const ERR_UNKNOWNERROR = "400"; export const ERR_NOSUCHNICK = "401"; +export const ERR_NOSUCHCHANNEL = "403"; +export const ERR_TOOMANYCHANNELS = "405"; export const ERR_UNKNOWNCOMMAND = "421"; export const ERR_NOMOTD = "422"; export const ERR_ERRONEUSNICKNAME = "432"; @@ -43,6 +45,10 @@ export const ERR_NEEDMOREPARAMS = "461"; export const ERR_NOPERMFORHOST = "463"; export const ERR_PASSWDMISMATCH = "464"; 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 export const ERR_UNAVAILRESOURCE = "437"; // Other