From 0dba9f560cdeb4248a287ccd5d7f6c2fcd9377bc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 13 Jun 2020 08:26:32 +0200 Subject: [PATCH] rework quicksy domain checks --- src/main/java/eu/siacs/conversations/Config.java | 2 +- src/main/java/eu/siacs/conversations/entities/Contact.java | 2 +- .../java/eu/siacs/conversations/entities/Conversation.java | 2 +- .../siacs/conversations/services/XmppConnectionService.java | 2 +- .../eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java | 2 +- src/main/java/eu/siacs/conversations/utils/JidHelper.java | 5 +++++ 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index f22561722..86d771740 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -41,7 +41,7 @@ public final class Config { public static final String DOMAIN_LOCK = null; //only allow account creation for this domain public static final String MAGIC_CREATE_DOMAIN = "conversations.im"; - public static final String QUICKSY_DOMAIN = "quicksy.im"; + public static final Jid QUICKSY_DOMAIN = Jid.of("quicksy.im"); public static final String CHANNEL_DISCOVERY = "https://search.jabber.network"; diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index d37646f78..7789a6686 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -134,7 +134,7 @@ public class Contact implements ListItem, Blockable { return this.systemName; } else if (!TextUtils.isEmpty(this.serverName)) { return this.serverName; - } else if (!TextUtils.isEmpty(this.presenceName) && ((QuickConversationsService.isQuicksy() && Config.QUICKSY_DOMAIN.equals(jid.getDomain().toEscapedString())) ||mutualPresenceSubscription())) { + } else if (!TextUtils.isEmpty(this.presenceName) && ((QuickConversationsService.isQuicksy() && JidHelper.isQuicksyDomain(jid.getDomain())) ||mutualPresenceSubscription())) { return this.presenceName; } else if (jid.getLocal() != null) { return JidHelper.localPartOrFallback(jid); diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 85d879578..83e49b9a5 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -1006,7 +1006,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl && !contact.isOwnServer() && !contact.showInContactList() && !contact.isSelf() - && !(Config.QUICKSY_DOMAIN != null && Config.QUICKSY_DOMAIN.equals(contact.getJid().toEscapedString())) + && !JidHelper.isQuicksyDomain(contact.getJid()) && sentMessagesCount() == 0; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 484ed3c0a..48030e7f3 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -4146,7 +4146,7 @@ public class XmppConnectionService extends Service { } } if (Config.QUICKSY_DOMAIN != null) { - hosts.remove(Config.QUICKSY_DOMAIN); //we only want to show this when we type a e164 number + hosts.remove(Config.QUICKSY_DOMAIN.toEscapedString()); //we only want to show this when we type a e164 number } if (Config.DOMAIN_LOCK != null) { hosts.add(Config.DOMAIN_LOCK); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java index 61177d0dc..f6017cf4d 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/KnownHostsAdapter.java @@ -27,7 +27,7 @@ public class KnownHostsAdapter extends ArrayAdapter { if (split.length == 1) { final String local = split[0].toLowerCase(Locale.ENGLISH); if (Config.QUICKSY_DOMAIN != null && E164_PATTERN.matcher(local).matches()) { - suggestions.add(local + '@' + Config.QUICKSY_DOMAIN); + suggestions.add(local + '@' + Config.QUICKSY_DOMAIN.toEscapedString()); } else { for (String domain : domains) { suggestions.add(local + '@' + domain); diff --git a/src/main/java/eu/siacs/conversations/utils/JidHelper.java b/src/main/java/eu/siacs/conversations/utils/JidHelper.java index 603899fca..c53af65ed 100644 --- a/src/main/java/eu/siacs/conversations/utils/JidHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/JidHelper.java @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import eu.siacs.conversations.Config; import eu.siacs.conversations.xmpp.InvalidJid; import eu.siacs.conversations.xmpp.Jid; @@ -59,4 +60,8 @@ public class JidHelper { } } + public static boolean isQuicksyDomain(final Jid jid) { + return Config.QUICKSY_DOMAIN != null && Config.QUICKSY_DOMAIN.equals(jid.getDomain()); + } + }