Don’t expose the complete reply object from the notice event.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / core / Core.java
index 1822ee6..509d30e 100644 (file)
@@ -41,6 +41,7 @@ import net.pterodactylus.irc.DccReceiver;
 import net.pterodactylus.irc.event.ChannelJoined;
 import net.pterodactylus.irc.event.ChannelLeft;
 import net.pterodactylus.irc.event.ChannelMessageReceived;
+import net.pterodactylus.irc.event.ChannelNotJoined;
 import net.pterodactylus.irc.event.ClientQuit;
 import net.pterodactylus.irc.event.ConnectionClosed;
 import net.pterodactylus.irc.event.ConnectionEstablished;
@@ -537,6 +538,18 @@ public class Core extends AbstractExecutionThreadService {
                }
        }
 
+       @Subscribe
+       public void channelNotJoined(ChannelNotJoined channelNotJoined) {
+               Optional<Network> network = getNetwork(channelNotJoined.connection());
+               if (!network.isPresent()) {
+                       return;
+               }
+
+               eventBus.post(new GenericMessage(
+                               format("Could not join %s/%s: %s", channelNotJoined.channel(),
+                                               network.get(), channelNotJoined.reason())));
+       }
+
        /**
         * Removes bots that leave a channel, or channels when it’s us that’s leaving.
         *
@@ -586,6 +599,19 @@ public class Core extends AbstractExecutionThreadService {
 
                /* have we been kicked? */
                if (nicknameMatchesConnection(kickedFromChannel.connection(), kickedFromChannel.kickee())) {
+                       Optional<Channel> channel = getChannel(network.get(), kickedFromChannel.channel());
+                       if (!channel.isPresent()) {
+                               /* maybe it was an extra channel? */
+                               channel = getExtraChannel(network.get(), kickedFromChannel.channel());
+                               if (!channel.isPresent()) {
+                                       /* okay, whatever. */
+                                       return;
+                               }
+
+                               extraChannels.remove(channel);
+                       } else {
+                               channels.remove(channel.get());
+                       }
                        eventBus.post(new GenericMessage(format(
                                        "Kicked from %s/%s by %s: %s",
                                        kickedFromChannel.channel(), network.get(),
@@ -704,7 +730,7 @@ public class Core extends AbstractExecutionThreadService {
                        return;
                }
 
-               eventBus.post(new GenericMessage(String.format("Notice from %s (%s): %s", privateNoticeReceived.reply().source().get(), network.get(), privateNoticeReceived.text())));
+               eventBus.post(new GenericMessage(String.format("Notice from %s (%s): %s", privateNoticeReceived.source(), network.get(), privateNoticeReceived.text())));
        }
 
        /**