diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/NickValidityChecker.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java b/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java new file mode 100644 index 000000000..0b4df771f --- /dev/null +++ b/src/main/java/de/pixart/messenger/utils/NickValidityChecker.java @@ -0,0 +1,33 @@ +package de.pixart.messenger.utils; + +import java.util.HashSet; +import java.util.Set; +import java.util.List; + +import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.xmpp.jid.InvalidJidException; +import de.pixart.messenger.xmpp.jid.Jid; + +public class NickValidityChecker { + + private static boolean check(final Conversation conversation, final String nick) { + Jid room = conversation.getJid(); + try { + Jid full = Jid.fromParts(room.getLocalpart(), room.getDomainpart(), nick); + return conversation.hasMessageWithCounterpart(full) + || conversation.getMucOptions().findUserByFullJid(full) != null; + } catch (InvalidJidException e) { + return false; + } + } + + public static boolean check(final Conversation conversation, final List<String> nicks) { + Set<String> previousNicks = new HashSet<>(nicks); + for(String previousNick : previousNicks) { + if (!NickValidityChecker.check(conversation,previousNick)) { + return false; + } + } + return true; + } +}
\ No newline at end of file |