From 4f647b5844e7c2b83dd7095e4520bfeeeb925084 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 7 Apr 2013 22:47:23 +0200 Subject: [PATCH] Fire events for private and channel messages. --- src/main/java/net/pterodactylus/irc/Connection.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index 92deeef..6f0bd12 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -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 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; -- 2.7.4