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 3b5e73205..1eff37956 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -804,12 +804,9 @@ public void onError(ErrorMessage msg) @Override public void onUserPrivMessage(UserPrivMsg msg) { - // TODO handle special formatting/color control codes in message - // (see also channel private messages) - ChatRoomIrcImpl chatroom = null; String user = msg.getSource().getNick(); - String text = msg.getText(); + String text = Utils.parse(msg.getText()); chatroom = IrcStack.this.joined.get(user); if (chatroom == null) { @@ -1066,11 +1063,9 @@ public void onChannelMessage(ChannelPrivMsg msg) if (!isThisChatRoom(msg.getChannelName())) return; - // TODO handle special formatting/color control codes in message - // (see also user private messages) - + String text = Utils.parse(msg.getText()); MessageIrcImpl message = - new MessageIrcImpl(msg.getText(), "text/plain", "UTF-8", null); + new MessageIrcImpl(text, "text/plain", "UTF-8", null); ChatRoomMemberIrcImpl member = new ChatRoomMemberIrcImpl(IrcStack.this.provider, this.chatroom, msg.getSource().getNick(), diff --git a/src/net/java/sip/communicator/impl/protocol/irc/Utils.java b/src/net/java/sip/communicator/impl/protocol/irc/Utils.java new file mode 100644 index 000000000..e10cc29eb --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/irc/Utils.java @@ -0,0 +1,58 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.irc; + +/** + * Some IRC-related utility methods. + * + * @author Danny van Heumen + */ +public final class Utils +{ + /** + * Starting value of HTML entities. + * + * The first 32 chars cannot be converted into HTML entities. + */ + private static final int START_OF_HTML_ENTITIES = 32; + + /** + * Private constructor since we do not need to construct anything. + */ + private Utils() + { + } + + /** + * Parse IRC text message and process possible control codes. + * + * 1. Remove chars which have a value < 32, since there are no equivalent + * HTML entities available when storing them in the history log. + * + * @param text message + * @return returns the processed message + */ + public static String parse(String text) + { + StringBuilder builder = new StringBuilder(text); + + // TODO support IRC control codes for formatting (now only removes them) + + for (int i = 0; i < builder.length(); ) + { + if (builder.charAt(i) < START_OF_HTML_ENTITIES) + { + builder.deleteCharAt(i); + } + else + { + // nothing to do here, go to next char + i++; + } + } + return builder.toString(); + } +}