diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-10-13 23:28:54 +0200 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2014-10-28 22:33:32 +0100 |
commit | f1540021c0416c6aa09e1cdf3cf03293b44a905a (patch) | |
tree | 424ec2e3d56e2b8a7fc200f0cf09c4b691424800 /src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java | |
parent | 8ec14739c1bbba18c8c1544fa3db5c7d864673f3 (diff) | |
download | jitsi-f1540021c0416c6aa09e1cdf3cf03293b44a905a.zip jitsi-f1540021c0416c6aa09e1cdf3cf03293b44a905a.tar.gz jitsi-f1540021c0416c6aa09e1cdf3cf03293b44a905a.tar.bz2 |
Support nick changes except on chat room join.
Diffstat (limited to 'src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java b/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java index 1ae842e..d5ba905 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IdentityManager.java @@ -6,6 +6,8 @@ */ package net.java.sip.communicator.impl.protocol.irc; +import java.util.*; + import net.java.sip.communicator.util.*; import com.ircclouds.irc.api.*; @@ -33,6 +35,22 @@ public class IdentityManager .getLogger(IdentityManager.class); /** + * Reserved symbols. These symbols have special meaning and cannot be + * used to start nick names. + */ + private static final Set<Character> RESERVED; + + /** + * Initialize RESERVED symbols set. + */ + static { + final HashSet<Character> reserved = new HashSet<Character>(); + reserved.add('#'); + reserved.add('&'); + RESERVED = Collections.unmodifiableSet(reserved); + } + + /** * The IRCApi instance. * * Instance must be thread-safe! @@ -93,6 +111,41 @@ public class IdentityManager } /** + * Set a new nick name. + * + * TODO Check ISUPPORT 'NICKLEN' for maximum nick length. + * + * @param nick new nick + */ + public void setNick(final String nick) + { + this.irc.changeNick(checkNick(nick)); + } + + /** + * Verify nick name. + * + * @param nick nick name + * @return returns nick name + */ + public static String checkNick(final String nick) + { + if (nick == null) + { + throw new IllegalArgumentException( + "a nick name must be provided"); + } + // TODO Add '+' and '!' to reserved symbols too? + if (RESERVED.contains(nick.charAt(0))) + { + throw new IllegalArgumentException( + "the nick name must not start with '#' or '&' " + + "since this is reserved for IRC channels"); + } + return nick; + } + + /** * Get the current identity string, based on nick, user and host of local * user. * @@ -213,16 +266,6 @@ public class IdentityManager private String host = null; /** - * Constructor. - * - * @param user user - * @param host host - */ - private Identity() - { - } - - /** * Set user. * * @param user the new user |