From dee13c82bf585f28ab52599261e6e1d011eaf443 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Tue, 9 Mar 2010 21:58:05 +0100 Subject: [PATCH] Implemented onNickChange IRC event --- src/org/yaaic/irc/IRCConnection.java | 40 ++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/org/yaaic/irc/IRCConnection.java b/src/org/yaaic/irc/IRCConnection.java index a934309..2105c32 100644 --- a/src/org/yaaic/irc/IRCConnection.java +++ b/src/org/yaaic/irc/IRCConnection.java @@ -20,6 +20,8 @@ along with Yaaic. If not, see . */ package org.yaaic.irc; +import java.util.Vector; + import android.content.Intent; import android.util.Log; @@ -263,7 +265,17 @@ public class IRCConnection extends PircBot { debug("Nick", oldNick + " " + newNick); - // XXX: Add message to all channels where oldNick / newNick is present + for (String target : getChannelsByNickname(newNick)) { + Channel channel = server.getChannel(target); + Message message = new Message(oldNick + " is now known as " + newNick); + message.setColor(Message.COLOR_GREEN); + channel.addMessage(message); + + Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE); + intent.putExtra(Broadcast.EXTRA_SERVER, server.getId()); + intent.putExtra(Broadcast.EXTRA_CHANNEL, target); + service.sendBroadcast(intent); + } } /** @@ -372,7 +384,7 @@ public class IRCConnection extends PircBot } Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE); -; + intent.putExtra(Broadcast.EXTRA_SERVER, server.getId()); intent.putExtra(Broadcast.EXTRA_CHANNEL, target); service.sendBroadcast(intent); @@ -428,6 +440,30 @@ public class IRCConnection extends PircBot } } + /** + * Get all channels where the user with the given nickname is online + * + * @param nickname + * @return Array of channel names + */ + private Vector getChannelsByNickname(String nickname) + { + Vector channels = new Vector(); + + for (String channel : this.getChannels()) { + for (User user : this.getUsers(channel)) { + if (user.getNick().equals(nickname)) { + channels.add(channel); + break; + } + } + } + + Log.d(TAG, "Found " + channels.size() + " channels for nickname " + nickname); + + return channels; + } + /** * Quits from the IRC server with default reason. */