2017-04-07 17:47:33 +00:00
|
|
|
package eu.siacs.conversations.utils;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2020-05-15 15:06:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2017-04-07 17:47:33 +00:00
|
|
|
|
|
|
|
public class NickValidityChecker {
|
|
|
|
|
|
|
|
private static boolean check(final Conversation conversation, final String nick) {
|
|
|
|
Jid room = conversation.getJid();
|
|
|
|
try {
|
2018-03-05 17:30:40 +00:00
|
|
|
Jid full = Jid.of(room.getLocal(), room.getDomain(), nick);
|
2017-04-07 17:47:33 +00:00
|
|
|
return conversation.hasMessageWithCounterpart(full)
|
|
|
|
|| conversation.getMucOptions().findUserByFullJid(full) != null;
|
2018-03-05 17:30:40 +00:00
|
|
|
} catch (IllegalArgumentException e) {
|
2017-04-07 17:47:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|