suggest quicksy.im when user enters e164 in enter jid dialog

This commit is contained in:
Daniel Gultsch 2018-10-25 20:50:10 +02:00
parent c9abe1c610
commit f7addc5d89
4 changed files with 21 additions and 4 deletions

View file

@ -41,6 +41,7 @@ public final class Config {
public static final String DOMAIN_LOCK = null; //only allow account creation for this domain 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 MAGIC_CREATE_DOMAIN = "conversations.im";
public static final String QUICKSY_DOMAIN = "quicksy.im";
public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox public static final boolean DISALLOW_REGISTRATION_IN_UI = false; //hide the register checkbox
public static final boolean USE_RANDOM_RESOURCE_ON_EVERY_BIND = false; public static final boolean USE_RANDOM_RESOURCE_ON_EVERY_BIND = false;

View file

@ -3544,12 +3544,15 @@ public class XmppConnectionService extends Service {
for (final Contact contact : account.getRoster().getContacts()) { for (final Contact contact : account.getRoster().getContacts()) {
if (contact.showInRoster()) { if (contact.showInRoster()) {
final String server = contact.getServer(); final String server = contact.getServer();
if (server != null && !hosts.contains(server)) { if (server != null) {
hosts.add(server); hosts.add(server);
} }
} }
} }
} }
if (Config.QUICKSY_DOMAIN != null) {
hosts.remove(Config.QUICKSY_DOMAIN); //we only want to show this when we type a e164 number
}
if (Config.DOMAIN_LOCK != null) { if (Config.DOMAIN_LOCK != null) {
hosts.add(Config.DOMAIN_LOCK); hosts.add(Config.DOMAIN_LOCK);
} }

View file

@ -7,9 +7,16 @@ import android.widget.Filter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern;
import eu.siacs.conversations.Config;
public class KnownHostsAdapter extends ArrayAdapter<String> { public class KnownHostsAdapter extends ArrayAdapter<String> {
private static Pattern E164_PATTERN = Pattern.compile("^\\+?[1-9]\\d{1,14}$");
private ArrayList<String> domains; private ArrayList<String> domains;
private Filter domainFilter = new Filter() { private Filter domainFilter = new Filter() {
@ -19,8 +26,12 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
final String[] split = constraint == null ? new String[0] : constraint.toString().split("@"); final String[] split = constraint == null ? new String[0] : constraint.toString().split("@");
if (split.length == 1) { if (split.length == 1) {
final String local = split[0].toLowerCase(Locale.ENGLISH); final String local = split[0].toLowerCase(Locale.ENGLISH);
for (String domain : domains) { if (Config.QUICKSY_DOMAIN != null && E164_PATTERN.matcher(local).matches()) {
suggestions.add(local + "@" + domain); suggestions.add(local + '@' + Config.QUICKSY_DOMAIN);
} else {
for (String domain : domains) {
suggestions.add(local + '@' + domain);
}
} }
} else if (split.length == 2) { } else if (split.length == 2) {
final String localPart = split[0].toLowerCase(Locale.ENGLISH); final String localPart = split[0].toLowerCase(Locale.ENGLISH);
@ -56,6 +67,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
public KnownHostsAdapter(Context context, int viewResourceId, Collection<String> mKnownHosts) { public KnownHostsAdapter(Context context, int viewResourceId, Collection<String> mKnownHosts) {
super(context, viewResourceId, new ArrayList<>()); super(context, viewResourceId, new ArrayList<>());
domains = new ArrayList<>(mKnownHosts); domains = new ArrayList<>(mKnownHosts);
Collections.sort(domains);
} }
public KnownHostsAdapter(Context context, int viewResourceId) { public KnownHostsAdapter(Context context, int viewResourceId) {
@ -65,6 +77,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
public void refresh(Collection<String> knownHosts) { public void refresh(Collection<String> knownHosts) {
domains = new ArrayList<>(knownHosts); domains = new ArrayList<>(knownHosts);
Collections.sort(domains);
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -125,7 +125,7 @@ public class QuickConversationsService {
private void createAccountAndWait(Phonenumber.PhoneNumber phoneNumber, final long timestamp) { private void createAccountAndWait(Phonenumber.PhoneNumber phoneNumber, final long timestamp) {
String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber); String local = PhoneNumberUtilWrapper.normalize(service, phoneNumber);
Log.d(Config.LOGTAG, "requesting verification for " + PhoneNumberUtilWrapper.normalize(service, phoneNumber)); Log.d(Config.LOGTAG, "requesting verification for " + PhoneNumberUtilWrapper.normalize(service, phoneNumber));
Jid jid = Jid.of(local, "quick.conversations.im", null); Jid jid = Jid.of(local, Config.QUICKSY_DOMAIN, null);
Account account = AccountUtils.getFirst(service); Account account = AccountUtils.getFirst(service);
if (account == null || !account.getJid().asBareJid().equals(jid.asBareJid())) { if (account == null || !account.getJid().asBareJid().equals(jid.asBareJid())) {
if (account != null) { if (account != null) {