Prevent UUID-only contacts from being added to GV1 groups.

This commit is contained in:
Greyson Parrelli
2020-07-29 23:04:35 -04:00
parent cc84901a49
commit 550b121990
10 changed files with 94 additions and 33 deletions

View File

@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.groups.ui.addmembers;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
@@ -58,14 +59,19 @@ public class AddMembersActivity extends PushContactSelectionActivity {
}
@Override
public void onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onContactSelected(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;
}
if (contactsFragment.hasQueryFilter()) {
getToolbar().clear();
}
if (contactsFragment.getSelectedContactsCount() >= 1) {
enableDone();
}
enableDone();
return true;
}
@Override

View File

@@ -39,13 +39,18 @@ public final class AddToGroupViewModel extends ViewModel {
events.postValue(new Event.CloseEvent());
} else if (groupRecipientIds.size() == 1) {
SignalExecutors.BOUNDED.execute(() -> {
Recipient recipient = Recipient.resolved(recipientId);
Recipient groupRecipient = Recipient.resolved(groupRecipientIds.get(0));
String recipientName = Recipient.resolved(recipientId).getDisplayName(context);
String recipientName = recipient.getDisplayName(context);
String groupName = groupRecipient.getDisplayName(context);
events.postValue(new Event.AddToSingleGroupConfirmationEvent(context.getResources().getString(R.string.AddToGroupActivity_add_member),
context.getResources().getString(R.string.AddToGroupActivity_add_s_to_s, recipientName, groupName),
groupRecipient, recipientName, groupName));
if (groupRecipient.getGroupId().get().isV1() && !recipient.hasE164()) {
events.postValue(new Event.LegacyGroupDenialEvent());
} else {
events.postValue(new Event.AddToSingleGroupConfirmationEvent(context.getResources().getString(R.string.AddToGroupActivity_add_member),
context.getResources().getString(R.string.AddToGroupActivity_add_s_to_s, recipientName, groupName),
groupRecipient, recipientName, groupName));
}
});
} else {
throw new AssertionError("Does not support multi-select");
@@ -107,6 +112,9 @@ public final class AddToGroupViewModel extends ViewModel {
return message;
}
}
static class LegacyGroupDenialEvent extends Event {
}
}
public static class Factory implements ViewModelProvider.Factory {

View File

@@ -91,6 +91,8 @@ public final class AddToGroupsActivity extends ContactSelectionActivity {
.setPositiveButton(android.R.string.ok, (dialog, which) -> viewModel.onAddToGroupsConfirmed(addEvent))
.setNegativeButton(android.R.string.cancel, null)
.show();
} else if (event instanceof Event.LegacyGroupDenialEvent) {
Toast.makeText(this, R.string.AddToGroupActivity_this_person_cant_be_added_to_legacy_groups, Toast.LENGTH_SHORT).show();
} else {
throw new AssertionError();
}
@@ -112,20 +114,23 @@ public final class AddToGroupsActivity extends ContactSelectionActivity {
}
@Override
public void onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
if (contactsFragment.isMulti()) {
if (contactsFragment.hasQueryFilter()) {
getToolbar().clear();
}
if (contactsFragment.getSelectedContactsCount() >= MINIMUM_GROUP_SELECT_SIZE) {
enableNext();
}
throw new UnsupportedOperationException("Not yet built to handle multi-select.");
// if (contactsFragment.hasQueryFilter()) {
// getToolbar().clear();
// }
//
// if (contactsFragment.getSelectedContactsCount() >= MINIMUM_GROUP_SELECT_SIZE) {
// enableNext();
// }
} else {
if (recipientId.isPresent()) {
viewModel.onContinueWithSelection(Collections.singletonList(recipientId.get()));
}
}
return true;
}
@Override

View File

@@ -8,6 +8,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import com.annimon.stream.Stream;
@@ -30,6 +31,8 @@ import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
import org.whispersystems.libsignal.util.guava.Optional;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class CreateGroupActivity extends ContactSelectionActivity {
@@ -90,14 +93,14 @@ public class CreateGroupActivity extends ContactSelectionActivity {
}
@Override
public void onContactSelected(Optional<RecipientId> recipientId, String number) {
public boolean onContactSelected(Optional<RecipientId> recipientId, String number) {
if (contactsFragment.hasQueryFilter()) {
getToolbar().clear();
}
if (contactsFragment.getSelectedContactsCount() >= MINIMUM_GROUP_SIZE) {
enableNext();
}
enableNext();
return true;
}
@Override
@@ -160,13 +163,31 @@ public class CreateGroupActivity extends ContactSelectionActivity {
stopwatch.split("capabilities");
resolved = Recipient.resolvedList(ids);
if (Stream.of(resolved).anyMatch(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED) &&
Stream.of(resolved).anyMatch(r -> !r.hasE164()))
{
Log.w(TAG, "Invalid GV1 group...");
ids = Collections.emptyList();
}
stopwatch.split("gv1-check");
return ids;
}, ids -> {
dismissibleDialog.dismiss();
stopwatch.stop(TAG);
startActivityForResult(AddGroupDetailsActivity.newIntent(this, ids), REQUEST_CODE_ADD_DETAILS);
if (ids.isEmpty()) {
new AlertDialog.Builder(this)
.setMessage(R.string.CreateGroupActivity_some_contacts_cannot_be_in_legacy_groups)
.setPositiveButton(android.R.string.ok, (d, w) -> d.dismiss())
.show();
} else {
startActivityForResult(AddGroupDetailsActivity.newIntent(this, ids), REQUEST_CODE_ADD_DETAILS);
}
});
}
}