diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index 258b36971..8c8e5756f 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -1167,6 +1167,23 @@ private static ChatRoomMemberRole convertMemberMode(final char modeSymbol) private final class ServerListener extends VariousMessageListenerAdapter { + /** + * IRC reply code for automatic reply containing away message. + */ + private static final int RPL_AWAY = 301; + + /** + * IRC error code for case of non-existing nick or channel name. + */ + private static final int ERR_NO_SUCH_NICK_CHANNEL = + IRCServerNumerics.NO_SUCH_NICK_CHANNEL; + + /** + * IRC reply code for end of list. + */ + private static final int RPL_LISTEND = + IRCServerNumerics.CHANNEL_NICKS_END_OF_LIST; + /** * IRCApi instance. */ @@ -1229,13 +1246,13 @@ public void onServerNumericMessage(final ServerNumericMessage msg) switch (code.intValue()) { - case IRCServerNumerics.CHANNEL_NICKS_END_OF_LIST: - // CHANNEL_NICKS_END_OF_LIST indicates the end of a nick list as - // you will receive when joining a channel. This is used as the - // indicator that we have joined a channel. Now we have to - // determine whether or not we already know about this - // particular join attempt. If not, we continue to inform Jitsi - // and to create a listener for this new chat room. + case RPL_LISTEND: + // This indicates the end of a nick list as you will receive + // when joining a channel. This is used as the indicator that we + // have joined a channel. Now we have to determine whether or + // not we already know about this particular join attempt. If + // not, we continue to inform Jitsi and to create a listener + // for this new chat room. final String text = msg.getText(); final String channelName = text.substring(0, text.indexOf(' ')); final ChatRoomIrcImpl chatRoom; @@ -1285,7 +1302,7 @@ public void onServerNumericMessage(final ServerNumericMessage msg) + "' completed."); break; - case IRCServerNumerics.NO_SUCH_NICK_CHANNEL: + case ERR_NO_SUCH_NICK_CHANNEL: // TODO Check if target is Contact, then update contact presence // status to off-line since the nick apparently does not exist // anymore. @@ -1325,6 +1342,21 @@ public void onServerNumericMessage(final ServerNumericMessage msg) .OFFLINE_MESSAGES_NOT_SUPPORTED); break; + case RPL_AWAY: + final String rawAwayText = msg.getText(); + final String awayUserNick = + rawAwayText.substring(0, rawAwayText.indexOf(' ')); + final String awayText = + rawAwayText.substring(rawAwayText.indexOf(' ') + 2); + final MessageIrcImpl awayMessage = + MessageIrcImpl.newAwayMessageFromIRC(awayText); + final Contact awayUser = + IrcStack.this.provider.getPersistentPresence() + .findOrCreateContactByID(awayUserNick); + IrcStack.this.provider.getBasicInstantMessaging() + .fireMessageReceived(awayMessage, awayUser); + break; + default: if (LOGGER.isTraceEnabled()) { diff --git a/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java index e77298e71..90a70ffc9 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java @@ -144,6 +144,20 @@ private static MessageIrcImpl newActionFromIRC(final String user, null); } + /** + * Construct the new away message. + * + * @param message the IRC away message + * @return returns a new message instance + */ + public static MessageIrcImpl newAwayMessageFromIRC(final String message) + { + String text = Utils.parseIrcMessage(message); + text = Utils.styleAsAwayMessage(text); + return new MessageIrcImpl(text, HTML_MIME_TYPE, DEFAULT_MIME_ENCODING, + null); + } + /** * Creates a message instance according to the specified parameters. * diff --git a/src/net/java/sip/communicator/impl/protocol/irc/Utils.java b/src/net/java/sip/communicator/impl/protocol/irc/Utils.java index d033947d5..05f86b7c8 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/Utils.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/Utils.java @@ -222,4 +222,15 @@ public static String styleAsAction(final String message, final String user) { return "*" + user + " " + message; } + + /** + * Format message as HTML-formatted away message. + * + * @param text away message + * @return returns HTML-formatted message + */ + public static String styleAsAwayMessage(final String text) + { + return "Away: " + text + ""; + } }