show escaped jid in most of the UI

for historical reasons we store unescaped variants in DB and use them in intents.
This commit is contained in:
Daniel Gultsch 2020-05-15 18:21:45 +02:00
parent b6703dbe38
commit ef7d4fca86
8 changed files with 40 additions and 20 deletions

View File

@ -116,13 +116,13 @@ public class ShortcutService {
} }
private static String getShortcutId(Contact contact) { private static String getShortcutId(Contact contact) {
return contact.getAccount().getJid().asBareJid().toString()+"#"+contact.getJid().asBareJid().toString(); return contact.getAccount().getJid().asBareJid().toEscapedString()+"#"+contact.getJid().asBareJid().toEscapedString();
} }
private Intent getShortcutIntent(Contact contact) { private Intent getShortcutIntent(Contact contact) {
Intent intent = new Intent(xmppConnectionService, StartConversationActivity.class); Intent intent = new Intent(xmppConnectionService, StartConversationActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("xmpp:"+contact.getJid().asBareJid().toString())); intent.setData(Uri.parse("xmpp:"+contact.getJid().asBareJid().toEscapedString()));
intent.putExtra("account",contact.getAccount().getJid().asBareJid().toString()); intent.putExtra("account",contact.getAccount().getJid().asBareJid().toString());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
return intent; return intent;

View File

@ -136,7 +136,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
AlertDialog.Builder builder = new AlertDialog.Builder( AlertDialog.Builder builder = new AlertDialog.Builder(
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, contact.getJid().toString())); builder.setMessage(getString(R.string.add_phone_book_text, contact.getJid().toEscapedString()));
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();
@ -411,9 +411,9 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
binding.detailsContactjid.setText(IrregularUnicodeDetector.style(this, contact.getJid())); binding.detailsContactjid.setText(IrregularUnicodeDetector.style(this, contact.getJid()));
String account; String account;
if (Config.DOMAIN_LOCK != null) { if (Config.DOMAIN_LOCK != null) {
account = contact.getAccount().getJid().getLocal(); account = contact.getAccount().getJid().getEscapedLocal();
} else { } else {
account = contact.getAccount().getJid().asBareJid().toString(); account = contact.getAccount().getJid().asBareJid().toEscapedString();
} }
binding.detailsAccount.setText(getString(R.string.using_account, account)); binding.detailsAccount.setText(getString(R.string.using_account, account));
AvatarWorkerTask.loadAvatar(contact, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size); AvatarWorkerTask.loadAvatar(contact, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size);

View File

@ -201,9 +201,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
final Jid jid; final Jid jid;
try { try {
if (mUsernameMode) { if (mUsernameMode) {
jid = Jid.of(binding.accountJid.getText().toString(), getUserModeDomain(), null); jid = Jid.ofEscaped(binding.accountJid.getText().toString(), getUserModeDomain(), null);
} else { } else {
jid = Jid.of(binding.accountJid.getText().toString()); jid = Jid.ofEscaped(binding.accountJid.getText().toString());
} }
} catch (final NullPointerException | IllegalArgumentException e) { } catch (final NullPointerException | IllegalArgumentException e) {
if (mUsernameMode) { if (mUsernameMode) {
@ -959,9 +959,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (init) { if (init) {
this.binding.accountJid.getEditableText().clear(); this.binding.accountJid.getEditableText().clear();
if (mUsernameMode) { if (mUsernameMode) {
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocal()); this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getEscapedLocal());
} else { } else {
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().asBareJid().toString()); this.binding.accountJid.getEditableText().append(this.mAccount.getJid().asBareJid().toEscapedString());
} }
this.binding.accountPassword.getEditableText().clear(); this.binding.accountPassword.getEditableText().clear();
this.binding.accountPassword.getEditableText().append(this.mAccount.getPassword()); this.binding.accountPassword.getEditableText().append(this.mAccount.getPassword());

View File

@ -155,7 +155,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
} }
final Jid contactJid; final Jid contactJid;
try { try {
contactJid = Jid.of(binding.jid.getText().toString()); contactJid = Jid.ofEscaped(binding.jid.getText().toString());
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
binding.jidLayout.setError(getActivity().getString(R.string.invalid_jid)); binding.jidLayout.setError(getActivity().getString(R.string.invalid_jid));
return; return;

View File

@ -855,11 +855,11 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
switchToConversationDoNotAppend(muc, invite.getBody()); switchToConversationDoNotAppend(muc, invite.getBody());
return true; return true;
} else { } else {
showJoinConferenceDialog(invite.getJid().asBareJid().toString()); showJoinConferenceDialog(invite.getJid().asBareJid().toEscapedString());
return false; return false;
} }
} else if (contacts.size() == 0) { } else if (contacts.size() == 0) {
showCreateContactDialog(invite.getJid().toString(), invite); showCreateContactDialog(invite.getJid().toEscapedString(), invite);
return false; return false;
} else if (contacts.size() == 1) { } else if (contacts.size() == 1) {
Contact contact = contacts.get(0); Contact contact = contacts.get(0);
@ -881,10 +881,10 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
if (mMenuSearchView != null) { if (mMenuSearchView != null) {
mMenuSearchView.expandActionView(); mMenuSearchView.expandActionView();
mSearchEditText.setText(""); mSearchEditText.setText("");
mSearchEditText.append(invite.getJid().toString()); mSearchEditText.append(invite.getJid().toEscapedString());
filter(invite.getJid().toString()); filter(invite.getJid().toEscapedString());
} else { } else {
mInitialSearchValue.push(invite.getJid().toString()); mInitialSearchValue.push(invite.getJid().toEscapedString());
} }
return true; return true;
} }

View File

@ -58,7 +58,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
if (Config.DOMAIN_LOCK != null) { if (Config.DOMAIN_LOCK != null) {
viewHolder.binding.accountJid.setText(account.getJid().getLocal()); viewHolder.binding.accountJid.setText(account.getJid().getLocal());
} else { } else {
viewHolder.binding.accountJid.setText(account.getJid().asBareJid().toString()); viewHolder.binding.accountJid.setText(account.getJid().asBareJid().toEscapedString());
} }
AvatarWorkerTask.loadAvatar(account, viewHolder.binding.accountImage, R.dimen.avatar); AvatarWorkerTask.loadAvatar(account, viewHolder.binding.accountImage, R.dimen.avatar);
viewHolder.binding.accountStatus.setText(getContext().getString(account.getStatus().getReadableId())); viewHolder.binding.accountStatus.setText(getContext().getString(account.getStatus().getReadableId()));

View File

@ -82,8 +82,8 @@ public class IrregularUnicodeDetector {
private static Spannable style(Jid jid, @ColorInt int color) { private static Spannable style(Jid jid, @ColorInt int color) {
PatternTuple patternTuple = find(jid); PatternTuple patternTuple = find(jid);
SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableStringBuilder builder = new SpannableStringBuilder();
if (jid.getLocal() != null && patternTuple.local != null) { if (jid.getEscapedLocal() != null && patternTuple.local != null) {
SpannableString local = new SpannableString(jid.getLocal()); SpannableString local = new SpannableString(jid.getEscapedLocal());
colorize(local, patternTuple.local, color); colorize(local, patternTuple.local, color);
builder.append(local); builder.append(local);
builder.append('@'); builder.append('@');
@ -258,8 +258,8 @@ public class IrregularUnicodeDetector {
private static PatternTuple of(Jid jid) { private static PatternTuple of(Jid jid) {
final Pattern localPattern; final Pattern localPattern;
if (jid.getLocal() != null) { if (jid.getEscapedLocal() != null) {
localPattern = create(findIrregularCodePoints(jid.getLocal())); localPattern = create(findIrregularCodePoints(jid.getEscapedLocal()));
} else { } else {
localPattern = null; localPattern = null;
} }

View File

@ -25,6 +25,26 @@ public interface Jid extends Comparable<Jid>, Serializable, CharSequence {
} }
} }
static Jid ofEscaped(CharSequence local, CharSequence domain, CharSequence resource) {
try {
if (resource == null) {
return new WrappedJid(
JidCreate.bareFrom(
Localpart.from(local.toString()),
Domainpart.from(domain.toString())
)
);
}
return new WrappedJid(JidCreate.entityFullFrom(
Localpart.from(local.toString()),
Domainpart.from(domain.toString()),
Resourcepart.from(resource.toString())
));
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
}
/** /**
* Creates a bare JID with only the domain part, e.g. <code>capulet.com</code> * Creates a bare JID with only the domain part, e.g. <code>capulet.com</code>
* *