Send event when a client parts a channel.
[xudocci.git] / src / main / java / net / pterodactylus / irc / Connection.java
index 239f0a2..15c8ff5 100644 (file)
@@ -39,6 +39,7 @@ import java.util.logging.Logger;
 import javax.net.SocketFactory;
 
 import net.pterodactylus.irc.event.ChannelJoined;
+import net.pterodactylus.irc.event.ChannelLeft;
 import net.pterodactylus.irc.event.ChannelMessageReceived;
 import net.pterodactylus.irc.event.ChannelNicknames;
 import net.pterodactylus.irc.event.ChannelNotJoined;
@@ -201,6 +202,19 @@ public class Connection extends AbstractExecutionThreadService implements Servic
        //
 
        /**
+        * Checks whether the given source is the client represented by this
+        * connection.
+        *
+        * @param source
+        *              The source to check
+        * @return {@code true} if this connection represents the given source, {@code
+        *         false} otherwise
+        */
+       public boolean isSource(Source source) {
+               return source.nick().isPresent() && source.nick().get().equals(nickname);
+       }
+
+       /**
         * Joins the given channel.
         *
         * @param channel
@@ -375,6 +389,8 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                } else if (command.equals("366")) {
                                        eventBus.post(new ChannelNicknames(this, parameters.get(1), nicks));
                                        nicks.clear();
+                               } else if (command.equalsIgnoreCase("PART")) {
+                                       eventBus.post(new ChannelLeft(this, parameters.get(0), reply.source().get(), parameters.get(1)));
 
                                /* common channel join errors. */
                                } else if (command.equals("474")) {