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) {
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) {
Intent intent = new Intent(xmppConnectionService, StartConversationActivity.class);
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.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);
return intent;

View File

@ -136,7 +136,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
AlertDialog.Builder builder = new AlertDialog.Builder(
ContactDetailsActivity.this);
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.setPositiveButton(getString(R.string.add), addToPhonebook);
builder.create().show();
@ -411,9 +411,9 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
binding.detailsContactjid.setText(IrregularUnicodeDetector.style(this, contact.getJid()));
String account;
if (Config.DOMAIN_LOCK != null) {
account = contact.getAccount().getJid().getLocal();
account = contact.getAccount().getJid().getEscapedLocal();
} else {
account = contact.getAccount().getJid().asBareJid().toString();
account = contact.getAccount().getJid().asBareJid().toEscapedString();
}
binding.detailsAccount.setText(getString(R.string.using_account, account));
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;
try {
if (mUsernameMode) {
jid = Jid.of(binding.accountJid.getText().toString(), getUserModeDomain(), null);
jid = Jid.ofEscaped(binding.accountJid.getText().toString(), getUserModeDomain(), null);
} else {
jid = Jid.of(binding.accountJid.getText().toString());
jid = Jid.ofEscaped(binding.accountJid.getText().toString());
}
} catch (final NullPointerException | IllegalArgumentException e) {
if (mUsernameMode) {
@ -959,9 +959,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (init) {
this.binding.accountJid.getEditableText().clear();
if (mUsernameMode) {
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getLocal());
this.binding.accountJid.getEditableText().append(this.mAccount.getJid().getEscapedLocal());
} 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().append(this.mAccount.getPassword());

View File

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

View File

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

View File

@ -58,7 +58,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
if (Config.DOMAIN_LOCK != null) {
viewHolder.binding.accountJid.setText(account.getJid().getLocal());
} 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);
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) {
PatternTuple patternTuple = find(jid);
SpannableStringBuilder builder = new SpannableStringBuilder();
if (jid.getLocal() != null && patternTuple.local != null) {
SpannableString local = new SpannableString(jid.getLocal());
if (jid.getEscapedLocal() != null && patternTuple.local != null) {
SpannableString local = new SpannableString(jid.getEscapedLocal());
colorize(local, patternTuple.local, color);
builder.append(local);
builder.append('@');
@ -258,8 +258,8 @@ public class IrregularUnicodeDetector {
private static PatternTuple of(Jid jid) {
final Pattern localPattern;
if (jid.getLocal() != null) {
localPattern = create(findIrregularCodePoints(jid.getLocal()));
if (jid.getEscapedLocal() != null) {
localPattern = create(findIrregularCodePoints(jid.getEscapedLocal()));
} else {
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>
*