diff --git a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java index 98cc492dc..89cd56b6f 100644 --- a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java @@ -15,6 +15,7 @@ import android.widget.ArrayAdapter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import eu.siacs.conversations.Config; @@ -41,6 +42,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected private static final String SANITY_CHECK_JID = "sanity_check_jid"; private KnownHostsAdapter knownHostsAdapter; + private Collection whitelistedDomains = Collections.emptyList(); private EnterJidDialogBinding binding; private AlertDialog dialog; @@ -155,19 +157,19 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected try { contactJid = Jid.of(binding.jid.getText().toString()); } catch (final IllegalArgumentException e) { - binding.jid.setError(getActivity().getString(R.string.invalid_jid)); + binding.jidLayout.setError(getActivity().getString(R.string.invalid_jid)); return; } if (!issuedWarning && sanityCheckJid) { if (contactJid.isDomainJid()) { - binding.jid.setError(getActivity().getString(R.string.this_looks_like_a_domain)); + binding.jidLayout.setError(getActivity().getString(R.string.this_looks_like_a_domain)); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add_anway); issuedWarning = true; return; } if (suspiciousSubDomain(contactJid.getDomain())) { - binding.jid.setError(getActivity().getString(R.string.this_looks_like_channel)); + binding.jidLayout.setError(getActivity().getString(R.string.this_looks_like_channel)); dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add_anway); issuedWarning = true; return; @@ -180,7 +182,9 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected dialog.dismiss(); } } catch (JidError error) { - binding.jid.setError(error.toString()); + binding.jidLayout.setError(error.toString()); + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add); + issuedWarning = false; } } } @@ -199,6 +203,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected if (activity instanceof XmppActivity) { Collection hosts = ((XmppActivity) activity).xmppConnectionService.getKnownHosts(); this.knownHostsAdapter.refresh(hosts); + this.whitelistedDomains = hosts; } } @@ -216,6 +221,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected public void afterTextChanged(Editable s) { if (issuedWarning) { dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add); + binding.jidLayout.setError(null); issuedWarning = false; } } @@ -245,7 +251,10 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected super.onDestroyView(); } - private static boolean suspiciousSubDomain(String domain) { + private boolean suspiciousSubDomain(String domain) { + if (this.whitelistedDomains.contains(domain)) { + return false; + } final String[] parts = domain.split("\\."); return parts.length >= 3 && SUSPICIOUS_DOMAINS.contains(parts[0]); } diff --git a/src/main/res/layout/enter_jid_dialog.xml b/src/main/res/layout/enter_jid_dialog.xml index fe58ea85f..1c20ef722 100644 --- a/src/main/res/layout/enter_jid_dialog.xml +++ b/src/main/res/layout/enter_jid_dialog.xml @@ -23,7 +23,7 @@ android:layout_height="wrap_content"/>