Fix to allow send of Signal invitation SMS to a single person.

Fixes #9970
This commit is contained in:
Alan Evans 2020-08-31 11:33:50 -03:00 committed by GitHub
parent 28d5ca7ed9
commit 40a8d21c15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 18 additions and 21 deletions

View File

@ -113,7 +113,7 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActivit
} }
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
return true; return true;
} }

View File

@ -70,7 +70,6 @@ import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.recipients.LiveRecipient; import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId; import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.StickyHeaderDecoration; import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.UsernameUtil; import org.thoughtcrime.securesms.util.UsernameUtil;
@ -475,7 +474,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
SelectedContact selected = SelectedContact.forUsername(recipient.getId(), contact.getNumber()); SelectedContact selected = SelectedContact.forUsername(recipient.getId(), contact.getNumber());
if (onContactSelectedListener != null) { if (onContactSelectedListener != null) {
if (onContactSelectedListener.onContactSelected(Optional.of(recipient.getId()), null)) { if (onContactSelectedListener.onBeforeContactSelected(Optional.of(recipient.getId()), null)) {
markContactSelected(selected); markContactSelected(selected);
cursorRecyclerViewAdapter.notifyItemChanged(recyclerView.getChildAdapterPosition(contact), ContactSelectionListAdapter.PAYLOAD_SELECTION_CHANGE); cursorRecyclerViewAdapter.notifyItemChanged(recyclerView.getChildAdapterPosition(contact), ContactSelectionListAdapter.PAYLOAD_SELECTION_CHANGE);
} }
@ -493,7 +492,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
}); });
} else { } else {
if (onContactSelectedListener != null) { if (onContactSelectedListener != null) {
if (onContactSelectedListener.onContactSelected(contact.getRecipientId(), contact.getNumber())) { if (onContactSelectedListener.onBeforeContactSelected(contact.getRecipientId(), contact.getNumber())) {
markContactSelected(selectedContact); markContactSelected(selectedContact);
cursorRecyclerViewAdapter.notifyItemChanged(recyclerView.getChildAdapterPosition(contact), ContactSelectionListAdapter.PAYLOAD_SELECTION_CHANGE); cursorRecyclerViewAdapter.notifyItemChanged(recyclerView.getChildAdapterPosition(contact), ContactSelectionListAdapter.PAYLOAD_SELECTION_CHANGE);
} }
@ -632,7 +631,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
public interface OnContactSelectedListener { public interface OnContactSelectedListener {
/** @return True if the contact is allowed to be selected, otherwise false. */ /** @return True if the contact is allowed to be selected, otherwise false. */
boolean onContactSelected(Optional<RecipientId> recipientId, String number); boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number);
void onContactDeselected(Optional<RecipientId> recipientId, String number); void onContactDeselected(Optional<RecipientId> recipientId, String number);
} }

View File

@ -40,7 +40,6 @@ import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener;
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask; import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
public class InviteActivity extends PassphraseRequiredActivity implements ContactSelectionListFragment.OnContactSelectedListener { public class InviteActivity extends PassphraseRequiredActivity implements ContactSelectionListFragment.OnContactSelectedListener {
@ -103,7 +102,7 @@ public class InviteActivity extends PassphraseRequiredActivity implements Contac
contactsFragment = (ContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment); contactsFragment = (ContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
inviteText.setText(getString(R.string.InviteActivity_lets_switch_to_signal, getString(R.string.install_url))); inviteText.setText(getString(R.string.InviteActivity_lets_switch_to_signal, getString(R.string.install_url)));
updateSmsButtonText(); updateSmsButtonText(contactsFragment.getSelectedContacts().size());
contactsFragment.setOnContactSelectedListener(this); contactsFragment.setOnContactSelectedListener(this);
shareButton.setOnClickListener(new ShareClickListener()); shareButton.setOnClickListener(new ShareClickListener());
@ -121,14 +120,14 @@ public class InviteActivity extends PassphraseRequiredActivity implements Contac
} }
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
updateSmsButtonText(); updateSmsButtonText(contactsFragment.getSelectedContacts().size() + 1);
return true; return true;
} }
@Override @Override
public void onContactDeselected(Optional<RecipientId> recipientId, String number) { public void onContactDeselected(Optional<RecipientId> recipientId, String number) {
updateSmsButtonText(); updateSmsButtonText(contactsFragment.getSelectedContacts().size());
} }
private void sendSmsInvites() { private void sendSmsInvites() {
@ -138,12 +137,11 @@ public class InviteActivity extends PassphraseRequiredActivity implements Contac
.toArray(new SelectedContact[0])); .toArray(new SelectedContact[0]));
} }
private void updateSmsButtonText() { private void updateSmsButtonText(int count) {
List<SelectedContact> selectedContacts = contactsFragment.getSelectedContacts();
smsSendButton.setText(getResources().getQuantityString(R.plurals.InviteActivity_send_sms_to_friends, smsSendButton.setText(getResources().getQuantityString(R.plurals.InviteActivity_send_sms_to_friends,
selectedContacts.size(), count,
selectedContacts.size())); count));
smsSendButton.setEnabled(!selectedContacts.isEmpty()); smsSendButton.setEnabled(count > 0);
} }
@Override public void onBackPressed() { @Override public void onBackPressed() {
@ -157,7 +155,7 @@ public class InviteActivity extends PassphraseRequiredActivity implements Contac
private void cancelSmsSelection() { private void cancelSmsSelection() {
setPrimaryColorsToolbarNormal(); setPrimaryColorsToolbarNormal();
contactsFragment.reset(); contactsFragment.reset();
updateSmsButtonText(); updateSmsButtonText(contactsFragment.getSelectedContacts().size());
ViewUtil.animateOut(smsSendFrame, slideOutAnimation, View.GONE); ViewUtil.animateOut(smsSendFrame, slideOutAnimation, View.GONE);
} }

View File

@ -60,7 +60,7 @@ public class NewConversationActivity extends ContactSelectionActivity
} }
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (recipientId.isPresent()) { if (recipientId.isPresent()) {
launch(Recipient.resolved(recipientId.get())); launch(Recipient.resolved(recipientId.get()));
} else { } else {

View File

@ -59,7 +59,7 @@ public class AddMembersActivity extends PushContactSelectionActivity {
} }
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (getGroupId().isV1() && recipientId.isPresent() && !Recipient.resolved(recipientId.get()).hasE164()) { if (getGroupId().isV1() && recipientId.isPresent() && !Recipient.resolved(recipientId.get()).hasE164()) {
Toast.makeText(this, R.string.AddMembersActivity__this_person_cant_be_added_to_legacy_groups, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.AddMembersActivity__this_person_cant_be_added_to_legacy_groups, Toast.LENGTH_SHORT).show();
return false; return false;

View File

@ -114,7 +114,7 @@ public final class AddToGroupsActivity extends ContactSelectionActivity {
} }
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (contactsFragment.isMulti()) { if (contactsFragment.isMulti()) {
throw new UnsupportedOperationException("Not yet built to handle multi-select."); throw new UnsupportedOperationException("Not yet built to handle multi-select.");
// if (contactsFragment.hasQueryFilter()) { // if (contactsFragment.hasQueryFilter()) {

View File

@ -93,7 +93,7 @@ public class CreateGroupActivity extends ContactSelectionActivity {
} }
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (contactsFragment.hasQueryFilter()) { if (contactsFragment.hasQueryFilter()) {
getToolbar().clear(); getToolbar().clear();
} }

View File

@ -150,7 +150,7 @@ public class ShareActivity extends PassphraseRequiredActivity
@Override @Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) { public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
SimpleTask.run(this.getLifecycle(), () -> { SimpleTask.run(this.getLifecycle(), () -> {
Recipient recipient; Recipient recipient;
if (recipientId.isPresent()) { if (recipientId.isPresent()) {