Fix refresh issues when creating group with first-time contacts.

This commit is contained in:
Greyson Parrelli 2022-01-21 17:55:11 -05:00
parent 22c396067d
commit 6e71514209
2 changed files with 26 additions and 9 deletions

View file

@ -29,9 +29,10 @@ public final class GroupsV2CapabilityChecker {
/** /**
* @param resolved A collection of resolved recipients. * @param resolved A collection of resolved recipients.
* @return True if a recipient needed to be refreshed, otherwise false.
*/ */
@WorkerThread @WorkerThread
public static void refreshCapabilitiesIfNecessary(@NonNull Collection<Recipient> resolved) throws IOException { public static boolean refreshCapabilitiesIfNecessary(@NonNull Collection<Recipient> resolved) throws IOException {
Set<RecipientId> needsRefresh = Stream.of(resolved) Set<RecipientId> needsRefresh = Stream.of(resolved)
.filter(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED) .filter(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED)
.map(Recipient::getId) .map(Recipient::getId)
@ -48,6 +49,10 @@ public final class GroupsV2CapabilityChecker {
throw new IOException("Recipient capability was not retrieved in time"); throw new IOException("Recipient capability was not retrieved in time");
} }
} }
return true;
} else {
return false;
} }
} }

View file

@ -39,7 +39,9 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors;
public class CreateGroupActivity extends ContactSelectionActivity { public class CreateGroupActivity extends ContactSelectionActivity {
@ -164,17 +166,18 @@ public class CreateGroupActivity extends ContactSelectionActivity {
SimpleProgressDialog.DismissibleDialog dismissibleDialog = SimpleProgressDialog.showDelayed(this); SimpleProgressDialog.DismissibleDialog dismissibleDialog = SimpleProgressDialog.showDelayed(this);
SimpleTask.run(getLifecycle(), () -> { SimpleTask.run(getLifecycle(), () -> {
List<RecipientId> ids = Stream.of(contactsFragment.getSelectedContacts()) List<RecipientId> ids = contactsFragment.getSelectedContacts()
.stream()
.map(selectedContact -> selectedContact.getOrCreateRecipientId(this)) .map(selectedContact -> selectedContact.getOrCreateRecipientId(this))
.toList(); .collect(Collectors.toList());
List<Recipient> resolved = Recipient.resolvedList(ids); List<Recipient> resolved = Recipient.resolvedList(ids);
stopwatch.split("resolve"); stopwatch.split("resolve");
List<Recipient> registeredChecks = Stream.of(resolved) Set<Recipient> registeredChecks = resolved.stream()
.filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN) .filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN)
.toList(); .collect(Collectors.toSet());
Log.i(TAG, "Need to do " + registeredChecks.size() + " registration checks."); Log.i(TAG, "Need to do " + registeredChecks.size() + " registration checks.");
@ -186,22 +189,31 @@ public class CreateGroupActivity extends ContactSelectionActivity {
} }
} }
if (registeredChecks.size() > 0) {
resolved = Recipient.resolvedList(ids);
}
stopwatch.split("registered"); stopwatch.split("registered");
List<Recipient> recipientsAndSelf = new ArrayList<>(resolved); List<Recipient> recipientsAndSelf = new ArrayList<>(resolved);
recipientsAndSelf.add(Recipient.self().resolve()); recipientsAndSelf.add(Recipient.self().resolve());
boolean neededRefresh = false;
if (!SignalStore.internalValues().gv2DoNotCreateGv2Groups()) { if (!SignalStore.internalValues().gv2DoNotCreateGv2Groups()) {
try { try {
GroupsV2CapabilityChecker.refreshCapabilitiesIfNecessary(recipientsAndSelf); neededRefresh = GroupsV2CapabilityChecker.refreshCapabilitiesIfNecessary(recipientsAndSelf);
} catch (IOException e) { } catch (IOException e) {
Log.w(TAG, "Failed to refresh all recipient capabilities.", e); Log.w(TAG, "Failed to refresh all recipient capabilities.", e);
} }
} }
if (neededRefresh) {
resolved = Recipient.resolvedList(ids);
}
stopwatch.split("capabilities"); stopwatch.split("capabilities");
resolved = Recipient.resolvedList(ids);
Pair<Boolean, List<RecipientId>> result; Pair<Boolean, List<RecipientId>> result;