Fire events for private and channel messages.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 7 Apr 2013 20:47:23 +0000 (22:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 7 Apr 2013 20:47:23 +0000 (22:47 +0200)
src/main/java/net/pterodactylus/irc/Connection.java

index 92deeef..6f0bd12 100644 (file)
@@ -36,6 +36,7 @@ import java.util.concurrent.SynchronousQueue;
 import javax.net.SocketFactory;
 
 import net.pterodactylus.irc.event.ChannelJoined;
+import net.pterodactylus.irc.event.ChannelMessageReceived;
 import net.pterodactylus.irc.event.ChannelNicknames;
 import net.pterodactylus.irc.event.ChannelNotJoined;
 import net.pterodactylus.irc.event.ChannelNotJoined.Reason;
@@ -45,6 +46,7 @@ import net.pterodactylus.irc.event.ConnectionFailed;
 import net.pterodactylus.irc.event.MotdReceived;
 import net.pterodactylus.irc.event.NicknameInUseReceived;
 import net.pterodactylus.irc.event.NoNicknameGivenReceived;
+import net.pterodactylus.irc.event.PrivateMessageReceived;
 import net.pterodactylus.irc.event.UnknownReplyReceived;
 import net.pterodactylus.irc.util.RandomNickname;
 
@@ -284,8 +286,17 @@ public class Connection extends AbstractExecutionThreadService implements Servic
                                String command = reply.command();
                                List<String> parameters = reply.parameters();
 
+                               /* most common events. */
+                               if (command.equalsIgnoreCase("PRIVMSG")) {
+                                       String recipient = parameters.get(0);
+                                       if (!channelTypes.contains(recipient.charAt(0))) {
+                                               eventBus.post(new PrivateMessageReceived(this, reply.source().get(), parameters.get(1)));
+                                       } else {
+                                               eventBus.post(new ChannelMessageReceived(this, recipient, reply.source().get(), parameters.get(1)));
+                                       }
+
                                /* replies 001-004 don’t hold information but they have to be sent on a successful connection. */
-                               if (command.equals("001")) {
+                               } else if (command.equals("001")) {
                                        connectionStatus |= 0x01;
                                } else if (command.equals("002")) {
                                        connectionStatus |= 0x02;