Prevent crash when adding group member by username.

This commit is contained in:
Greyson Parrelli
2023-01-04 09:53:20 -05:00
parent 4de27482bb
commit b9fc36be5a
2 changed files with 5 additions and 1 deletions

View File

@@ -667,7 +667,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
SelectedContact selectedContact = contact.isUsernameType() ? SelectedContact.forUsername(contact.getRecipientId().orElse(null), contact.getNumber()) SelectedContact selectedContact = contact.isUsernameType() ? SelectedContact.forUsername(contact.getRecipientId().orElse(null), contact.getNumber())
: SelectedContact.forPhone(contact.getRecipientId().orElse(null), contact.getNumber()); : SelectedContact.forPhone(contact.getRecipientId().orElse(null), contact.getNumber());
if (!canSelectSelf && Recipient.self().getId().equals(selectedContact.getOrCreateRecipientId(requireContext()))) { if (!canSelectSelf && !selectedContact.hasUsername() && Recipient.self().getId().equals(selectedContact.getOrCreateRecipientId(requireContext()))) {
Toast.makeText(requireContext(), R.string.ContactSelectionListFragment_you_do_not_need_to_add_yourself_to_the_group, Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), R.string.ContactSelectionListFragment_you_do_not_need_to_add_yourself_to_the_group, Toast.LENGTH_SHORT).show();
return; return;
} }

View File

@@ -46,6 +46,10 @@ public final class SelectedContact {
} }
} }
public boolean hasUsername() {
return username != null;
}
/** /**
* Returns true when non-null recipient ids match, and false if not. * Returns true when non-null recipient ids match, and false if not.
* <p> * <p>