Add handler for when a channel can not be joined.
[xudocci.git] / src / main / java / net / pterodactylus / irc / Connection.java
index cc1f9c8..6354c90 100644 (file)
@@ -40,6 +40,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.net.SocketFactory;
 
+import net.pterodactylus.irc.connection.ChannelNotJoinedHandler;
 import net.pterodactylus.irc.connection.ConnectionEstablishHandler;
 import net.pterodactylus.irc.event.ChannelJoined;
 import net.pterodactylus.irc.event.ChannelLeft;
@@ -382,6 +383,7 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                        Set<Character> channelTypes = Sets.newHashSet();
 
                        ConnectionEstablishHandler connectionEstablishHandler = new ConnectionEstablishHandler(eventBus, this);
+                       ChannelNotJoinedHandler channelNotJoinedHandler = new ChannelNotJoinedHandler(eventBus, this);
 
                        while (connected) {
                                Reply reply = connectionHandler.readReply();
@@ -453,15 +455,8 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                } else if (command.equalsIgnoreCase("QUIT")) {
                                        eventBus.post(new ClientQuit(this, reply.source().get(), parameters.get(0)));
 
-                               /* common channel join errors. */
-                               } else if (command.equals("474")) {
-                                       eventBus.post(new ChannelNotJoined(this, parameters.get(1), Reason.banned));
-                               } else if (command.equals("473")) {
-                                       eventBus.post(new ChannelNotJoined(this, parameters.get(1), Reason.inviteOnly));
-                               } else if (command.equals("475")) {
-                                       eventBus.post(new ChannelNotJoined(this, parameters.get(1), Reason.badChannelKey));
-                               } else if (command.equals("477")) {
-                                       eventBus.post(new ChannelNotJoined(this, parameters.get(1), Reason.registeredNicknamesOnly));
+                               } else if (channelNotJoinedHandler.willHandle(reply)) {
+                                       channelNotJoinedHandler.handleReply(reply);
 
                                /* basic connection housekeeping. */
                                } else if (command.equalsIgnoreCase("PING")) {