optionally lock conference domains as well and hide known domains in ui

This commit is contained in:
Daniel Gultsch 2016-02-24 16:53:19 +01:00
parent d1a456f3e3
commit bbede8bbeb
10 changed files with 76 additions and 22 deletions

View File

@ -42,6 +42,10 @@ 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 CONFERENCE_DOMAIN_LOCK = null; //only allow conference creation for this domain
public static final boolean LOCK_DOMAINS_IN_CONVERSATIONS = false; //only add contacts and conferences for own domains
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 ALLOW_NON_TLS_CONNECTIONS = false; //very dangerous. you should have a good reason to set this to true public static final boolean ALLOW_NON_TLS_CONNECTIONS = false; //very dangerous. you should have a good reason to set this to true
public static final boolean FORCE_ORBOT = false; // always use TOR public static final boolean FORCE_ORBOT = false; // always use TOR

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -57,6 +58,18 @@ public class Bookmark extends Element implements ListItem {
} }
} }
@Override
public String getDisplayJid() {
Jid jid = getJid();
if (Config.LOCK_DOMAINS_IN_CONVERSATIONS && jid != null && jid.getDomainpart().equals(Config.CONFERENCE_DOMAIN_LOCK)) {
return jid.getLocalpart();
} else if (jid != null) {
return jid.toString();
} else {
return null;
}
}
@Override @Override
public Jid getJid() { public Jid getJid() {
return this.getAttributeAsJid("jid"); return this.getAttributeAsJid("jid");

View File

@ -121,6 +121,17 @@ public class Contact implements ListItem, Blockable {
} }
} }
@Override
public String getDisplayJid() {
if (Config.LOCK_DOMAINS_IN_CONVERSATIONS && jid != null && jid.getDomainpart().equals(Config.DOMAIN_LOCK)) {
return jid.getLocalpart();
} else if (jid != null) {
return jid.toString();
} else {
return null;
}
}
public String getProfilePhoto() { public String getProfilePhoto() {
return this.photoUri; return this.photoUri;
} }

View File

@ -5,13 +5,15 @@ import java.util.List;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
public interface ListItem extends Comparable<ListItem> { public interface ListItem extends Comparable<ListItem> {
public String getDisplayName(); String getDisplayName();
public Jid getJid(); String getDisplayJid();
public List<Tag> getTags(); Jid getJid();
public final class Tag { List<Tag> getTags();
final class Tag {
private final String name; private final String name;
private final int color; private final int color;
@ -29,5 +31,5 @@ public interface ListItem extends Comparable<ListItem> {
} }
} }
public boolean match(final String needle); boolean match(final String needle);
} }

View File

@ -6,7 +6,6 @@ import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextMenu; import android.view.ContextMenu;
@ -512,7 +511,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
mAccountJid.setText(getString(R.string.using_account, account)); mAccountJid.setText(getString(R.string.using_account, account));
mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48))); mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
setTitle(mConversation.getName()); setTitle(mConversation.getName());
if (Config.LOCK_DOMAINS_IN_CONVERSATIONS && mConversation.getJid().getDomainpart().equals(Config.CONFERENCE_DOMAIN_LOCK)) {
mFullJid.setText(mConversation.getJid().getLocalpart());
} else {
mFullJid.setText(mConversation.getJid().toBareJid().toString()); mFullJid.setText(mConversation.getJid().toBareJid().toString());
}
mYourNick.setText(mucOptions.getActualNick()); mYourNick.setText(mucOptions.getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
if (mucOptions.online()) { if (mucOptions.online()) {

View File

@ -139,7 +139,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
ContactDetailsActivity.this); ContactDetailsActivity.this);
builder.setTitle(getString(R.string.action_add_phone_book)); builder.setTitle(getString(R.string.action_add_phone_book));
builder.setMessage(getString(R.string.add_phone_book_text, builder.setMessage(getString(R.string.add_phone_book_text,
contact.getJid())); contact.getDisplayJid()));
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add), addToPhonebook); builder.setPositiveButton(getString(R.string.add), addToPhonebook);
builder.create().show(); builder.create().show();
@ -236,7 +236,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
builder.setTitle(getString(R.string.action_delete_contact)) builder.setTitle(getString(R.string.action_delete_contact))
.setMessage( .setMessage(
getString(R.string.remove_contact_text, getString(R.string.remove_contact_text,
contact.getJid())) contact.getDisplayJid()))
.setPositiveButton(getString(R.string.delete), .setPositiveButton(getString(R.string.delete),
removeFromRoster).create().show(); removeFromRoster).create().show();
break; break;
@ -358,10 +358,10 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
} }
if (contact.getPresences().size() > 1) { if (contact.getPresences().size() > 1) {
contactJidTv.setText(contact.getJid() + " (" contactJidTv.setText(contact.getDisplayJid() + " ("
+ contact.getPresences().size() + ")"); + contact.getPresences().size() + ")");
} else { } else {
contactJidTv.setText(contact.getJid().toString()); contactJidTv.setText(contact.getDisplayJid());
} }
String account; String account;
if (Config.DOMAIN_LOCK != null) { if (Config.DOMAIN_LOCK != null) {

View File

@ -2,13 +2,12 @@ package eu.siacs.conversations.ui;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import java.util.List; import java.util.List;
@ -44,12 +43,17 @@ public class EnterJidDialog {
final String title, final String positiveButton, final String title, final String positiveButton,
final String prefilledJid, final String account, boolean allowEditJid final String prefilledJid, final String account, boolean allowEditJid
) { ) {
final boolean lock = Config.LOCK_DOMAINS_IN_CONVERSATIONS && Config.DOMAIN_LOCK != null;
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title); builder.setTitle(title);
View dialogView = LayoutInflater.from(context).inflate(R.layout.enter_jid_dialog, null); View dialogView = LayoutInflater.from(context).inflate(R.layout.enter_jid_dialog, null);
final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
jabberIdDesc.setText(lock ? R.string.username : R.string.account_settings_jabber_id);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid); final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
if (!lock) {
jid.setAdapter(new KnownHostsAdapter(context, android.R.layout.simple_list_item_1, knownHosts)); jid.setAdapter(new KnownHostsAdapter(context, android.R.layout.simple_list_item_1, knownHosts));
}
if (prefilledJid != null) { if (prefilledJid != null) {
jid.append(prefilledJid); jid.append(prefilledJid);
if (!allowEditJid) { if (!allowEditJid) {
@ -60,6 +64,7 @@ public class EnterJidDialog {
} }
} }
jid.setHint(Config.LOCK_DOMAINS_IN_CONVERSATIONS && Config.DOMAIN_LOCK != null ? R.string.username_hint : R.string.account_settings_example_jabber_id);
if (account == null) { if (account == null) {
StartConversationActivity.populateAccountSpinner(context, activatedAccounts, spinner); StartConversationActivity.populateAccountSpinner(context, activatedAccounts, spinner);
@ -95,9 +100,13 @@ public class EnterJidDialog {
} }
final Jid contactJid; final Jid contactJid;
try { try {
if (lock) {
contactJid = Jid.fromParts(jid.getText().toString(), Config.DOMAIN_LOCK, null);
} else {
contactJid = Jid.fromString(jid.getText().toString()); contactJid = Jid.fromString(jid.getText().toString());
}
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
jid.setError(context.getString(R.string.invalid_jid)); jid.setError(context.getString(lock ? R.string.invalid_username : R.string.invalid_jid));
return; return;
} }

View File

@ -44,6 +44,7 @@ import android.widget.Checkable;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentIntegrator;
@ -64,7 +65,6 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.adapter.ListItemAdapter; import eu.siacs.conversations.ui.adapter.ListItemAdapter;
@ -390,7 +390,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null); final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid); final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
final boolean lock = Config.LOCK_DOMAINS_IN_CONVERSATIONS && Config.CONFERENCE_DOMAIN_LOCK != null;
final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
jabberIdDesc.setText(lock ? R.string.conference_name : R.string.conference_address);
jid.setHint(lock ? R.string.conference_name : R.string.conference_address_example);
if (!lock) {
jid.setAdapter(new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, mKnownConferenceHosts)); jid.setAdapter(new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, mKnownConferenceHosts));
}
if (prefilledJid != null) { if (prefilledJid != null) {
jid.append(prefilledJid); jid.append(prefilledJid);
} }
@ -416,9 +422,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
final Jid conferenceJid; final Jid conferenceJid;
try { try {
if (lock) {
conferenceJid = Jid.fromParts(jid.getText().toString(),Config.CONFERENCE_DOMAIN_LOCK, null);
} else {
conferenceJid = Jid.fromString(jid.getText().toString()); conferenceJid = Jid.fromString(jid.getText().toString());
}
} catch (final InvalidJidException e) { } catch (final InvalidJidException e) {
jid.setError(getString(R.string.invalid_jid)); jid.setError(getString(lock ? R.string.invalid_conference_name : R.string.invalid_jid));
return; return;
} }

View File

@ -76,10 +76,10 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
tagLayout.addView(tv); tagLayout.addView(tv);
} }
} }
final Jid jid = item.getJid(); final String jid = item.getDisplayJid();
if (jid != null) { if (jid != null) {
tvJid.setVisibility(View.VISIBLE); tvJid.setVisibility(View.VISIBLE);
tvJid.setText(jid.toString()); tvJid.setText(jid);
} else { } else {
tvJid.setVisibility(View.GONE); tvJid.setVisibility(View.GONE);
} }

View File

@ -522,6 +522,8 @@
<string name="username">Username</string> <string name="username">Username</string>
<string name="username_hint">Username</string> <string name="username_hint">Username</string>
<string name="invalid_username">This is not a valid username</string> <string name="invalid_username">This is not a valid username</string>
<string name="conference_name">Conference name</string>
<string name="invalid_conference_name">This is not a valid conference name</string>
<string name="download_failed_server_not_found">Download failed: Server not found</string> <string name="download_failed_server_not_found">Download failed: Server not found</string>
<string name="download_failed_file_not_found">Download failed: File not found</string> <string name="download_failed_file_not_found">Download failed: File not found</string>
<string name="download_failed_could_not_connect">Download failed: Could not connect to host</string> <string name="download_failed_could_not_connect">Download failed: Could not connect to host</string>