aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-04-13 21:44:50 +0200
committerChristian Schneppe <christian@pix-art.de>2017-04-13 21:44:50 +0200
commitbc03a692264de9e6b06539a8abf17b69cc65a2ff (patch)
tree0a44340ca40635a78c4cd3b3b3e881ecda1a9e62 /src/main/java/de/pixart/messenger/utils
parentc42d2759f89a39d6caada419653b2b05bf38ef3d (diff)
be more careful with corner cases when mentioning multiple people
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils')
-rw-r--r--src/main/java/de/pixart/messenger/utils/NickValidityChecker.java33
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