mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-25 19:29:30 +00:00
Allow empty group creation.
This commit is contained in:
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.groups.ui.creategroup;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Pair;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
@@ -40,7 +41,6 @@ public class CreateGroupActivity extends ContactSelectionActivity {
|
||||
|
||||
private static final String TAG = Log.tag(CreateGroupActivity.class);
|
||||
|
||||
private static final int MINIMUM_GROUP_SIZE = 1;
|
||||
private static final short REQUEST_CODE_ADD_DETAILS = 17275;
|
||||
|
||||
private View next;
|
||||
@@ -68,7 +68,6 @@ public class CreateGroupActivity extends ContactSelectionActivity {
|
||||
|
||||
next = findViewById(R.id.next);
|
||||
|
||||
disableNext();
|
||||
next.setOnClickListener(v -> handleNextPressed());
|
||||
}
|
||||
|
||||
@@ -107,10 +106,6 @@ public class CreateGroupActivity extends ContactSelectionActivity {
|
||||
if (contactsFragment.hasQueryFilter()) {
|
||||
getToolbar().clear();
|
||||
}
|
||||
|
||||
if (contactsFragment.getSelectedContactsCount() < MINIMUM_GROUP_SIZE) {
|
||||
disableNext();
|
||||
}
|
||||
}
|
||||
|
||||
private void enableNext() {
|
||||
@@ -167,28 +162,33 @@ public class CreateGroupActivity extends ContactSelectionActivity {
|
||||
|
||||
resolved = Recipient.resolvedList(ids);
|
||||
|
||||
Pair<Boolean, List<RecipientId>> result;
|
||||
|
||||
boolean gv2 = Stream.of(recipientsAndSelf).allMatch(r -> r.getGroupsV2Capability() == Recipient.Capability.SUPPORTED);
|
||||
if (!gv2 && Stream.of(resolved).anyMatch(r -> !r.hasE164()))
|
||||
{
|
||||
Log.w(TAG, "Invalid GV1 group...");
|
||||
ids = Collections.emptyList();
|
||||
result = Pair.create(false, ids);
|
||||
} else {
|
||||
result = Pair.create(true, ids);
|
||||
}
|
||||
|
||||
stopwatch.split("gv1-check");
|
||||
|
||||
return ids;
|
||||
}, ids -> {
|
||||
return result;
|
||||
}, result -> {
|
||||
dismissibleDialog.dismiss();
|
||||
|
||||
stopwatch.stop(TAG);
|
||||
|
||||
if (ids.isEmpty()) {
|
||||
if (result.first) {
|
||||
startActivityForResult(AddGroupDetailsActivity.newIntent(this, result.second), REQUEST_CODE_ADD_DETAILS);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -106,13 +106,7 @@ public class AddGroupDetailsFragment extends LoggingFragment {
|
||||
name.addTextChangedListener(new AfterTextChanged(editable -> viewModel.setName(editable.toString())));
|
||||
toolbar.setNavigationOnClickListener(unused -> callback.onNavigationButtonPressed());
|
||||
create.setOnClickListener(v -> handleCreateClicked());
|
||||
viewModel.getMembers().observe(getViewLifecycleOwner(), recipients -> {
|
||||
members.setMembers(recipients);
|
||||
if (recipients.isEmpty()) {
|
||||
toast(R.string.AddGroupDetailsFragment__groups_require_at_least_two_members);
|
||||
callback.onNavigationButtonPressed();
|
||||
}
|
||||
});
|
||||
viewModel.getMembers().observe(getViewLifecycleOwner(), members::setMembers);
|
||||
viewModel.getCanSubmitForm().observe(getViewLifecycleOwner(), isFormValid -> setCreateEnabled(isFormValid, true));
|
||||
viewModel.getIsMms().observe(getViewLifecycleOwner(), isMms -> {
|
||||
mmsWarning.setVisibility(isMms ? View.VISIBLE : View.GONE);
|
||||
@@ -230,10 +224,6 @@ public class AddGroupDetailsFragment extends LoggingFragment {
|
||||
case ERROR_INVALID_NAME:
|
||||
name.setError(getString(R.string.AddGroupDetailsFragment__this_field_is_required));
|
||||
break;
|
||||
case ERROR_INVALID_MEMBER_COUNT:
|
||||
toast(R.string.AddGroupDetailsFragment__groups_require_at_least_two_members);
|
||||
callback.onNavigationButtonPressed();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected error: " + error.getErrorType().name());
|
||||
}
|
||||
|
@@ -124,11 +124,6 @@ public final class AddGroupDetailsViewModel extends ViewModel {
|
||||
return;
|
||||
}
|
||||
|
||||
if (memberIds.isEmpty()) {
|
||||
groupCreateResult.postValue(GroupCreateResult.error(GroupCreateResult.Error.Type.ERROR_INVALID_MEMBER_COUNT));
|
||||
return;
|
||||
}
|
||||
|
||||
repository.createGroup(memberIds,
|
||||
avatarBytes,
|
||||
groupName,
|
||||
|
@@ -86,8 +86,7 @@ abstract class GroupCreateResult {
|
||||
ERROR_IO,
|
||||
ERROR_BUSY,
|
||||
ERROR_FAILED,
|
||||
ERROR_INVALID_NAME,
|
||||
ERROR_INVALID_MEMBER_COUNT
|
||||
ERROR_INVALID_NAME
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user