Skip to content

Commit

Permalink
Fix to allow send of Signal invitation SMS to a single person.
Browse files Browse the repository at this point in the history
Fixes #9970
  • Loading branch information
alan-signal committed Aug 31, 2020
1 parent 28d5ca7 commit 40a8d21
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void onRefresh() {
}

@Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.UsernameUtil;
Expand Down Expand Up @@ -475,7 +474,7 @@ public void onItemClick(ContactSelectionListItem contact) {
SelectedContact selected = SelectedContact.forUsername(recipient.getId(), contact.getNumber());

if (onContactSelectedListener != null) {
if (onContactSelectedListener.onContactSelected(Optional.of(recipient.getId()), null)) {
if (onContactSelectedListener.onBeforeContactSelected(Optional.of(recipient.getId()), null)) {
markContactSelected(selected);
cursorRecyclerViewAdapter.notifyItemChanged(recyclerView.getChildAdapterPosition(contact), ContactSelectionListAdapter.PAYLOAD_SELECTION_CHANGE);
}
Expand All @@ -493,7 +492,7 @@ public void onItemClick(ContactSelectionListItem contact) {
});
} else {
if (onContactSelectedListener != null) {
if (onContactSelectedListener.onContactSelected(contact.getRecipientId(), contact.getNumber())) {
if (onContactSelectedListener.onBeforeContactSelected(contact.getRecipientId(), contact.getNumber())) {
markContactSelected(selectedContact);
cursorRecyclerViewAdapter.notifyItemChanged(recyclerView.getChildAdapterPosition(contact), ContactSelectionListAdapter.PAYLOAD_SELECTION_CHANGE);
}
Expand Down Expand Up @@ -632,7 +631,7 @@ private void smoothScrollChipsToEnd() {

public interface OnContactSelectedListener {
/** @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);
}

Expand Down
20 changes: 9 additions & 11 deletions app/src/main/java/org/thoughtcrime/securesms/InviteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
import org.whispersystems.libsignal.util.guava.Optional;

import java.util.List;
import java.util.concurrent.ExecutionException;

public class InviteActivity extends PassphraseRequiredActivity implements ContactSelectionListFragment.OnContactSelectedListener {
Expand Down Expand Up @@ -103,7 +102,7 @@ private void initializeResources() {
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)));
updateSmsButtonText();
updateSmsButtonText(contactsFragment.getSelectedContacts().size());

contactsFragment.setOnContactSelectedListener(this);
shareButton.setOnClickListener(new ShareClickListener());
Expand All @@ -121,14 +120,14 @@ private Animation loadAnimation(@AnimRes int animResId) {
}

@Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
updateSmsButtonText();
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
updateSmsButtonText(contactsFragment.getSelectedContacts().size() + 1);
return true;
}

@Override
public void onContactDeselected(Optional<RecipientId> recipientId, String number) {
updateSmsButtonText();
updateSmsButtonText(contactsFragment.getSelectedContacts().size());
}

private void sendSmsInvites() {
Expand All @@ -138,12 +137,11 @@ private void sendSmsInvites() {
.toArray(new SelectedContact[0]));
}

private void updateSmsButtonText() {
List<SelectedContact> selectedContacts = contactsFragment.getSelectedContacts();
private void updateSmsButtonText(int count) {
smsSendButton.setText(getResources().getQuantityString(R.plurals.InviteActivity_send_sms_to_friends,
selectedContacts.size(),
selectedContacts.size()));
smsSendButton.setEnabled(!selectedContacts.isEmpty());
count,
count));
smsSendButton.setEnabled(count > 0);
}

@Override public void onBackPressed() {
Expand All @@ -157,7 +155,7 @@ private void updateSmsButtonText() {
private void cancelSmsSelection() {
setPrimaryColorsToolbarNormal();
contactsFragment.reset();
updateSmsButtonText();
updateSmsButtonText(contactsFragment.getSelectedContacts().size());
ViewUtil.animateOut(smsSendFrame, slideOutAnimation, View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onCreate(Bundle bundle, boolean ready) {
}

@Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (recipientId.isPresent()) {
launch(Recipient.resolved(recipientId.get()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void initializeToolbar() {
}

@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()) {
Toast.makeText(this, R.string.AddMembersActivity__this_person_cant_be_added_to_legacy_groups, Toast.LENGTH_SHORT).show();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (contactsFragment.isMulti()) {
throw new UnsupportedOperationException("Not yet built to handle multi-select.");
// if (contactsFragment.hasQueryFilter()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
}

@Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
if (contactsFragment.hasQueryFilter()) {
getToolbar().clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void onBackPressed() {


@Override
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onBeforeContactSelected(Optional<RecipientId> recipientId, String number) {
SimpleTask.run(this.getLifecycle(), () -> {
Recipient recipient;
if (recipientId.isPresent()) {
Expand Down

0 comments on commit 40a8d21

Please sign in to comment.