From 6e71514209abd03f967f7529cc6496d437fe61a1 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 21 Jan 2022 17:55:11 -0500 Subject: [PATCH] Fix refresh issues when creating group with first-time contacts. --- .../groups/GroupsV2CapabilityChecker.java | 7 ++++- .../ui/creategroup/CreateGroupActivity.java | 28 +++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupsV2CapabilityChecker.java b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupsV2CapabilityChecker.java index a8296e7159..d232eeed98 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupsV2CapabilityChecker.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupsV2CapabilityChecker.java @@ -29,9 +29,10 @@ public final class GroupsV2CapabilityChecker { /** * @param resolved A collection of resolved recipients. + * @return True if a recipient needed to be refreshed, otherwise false. */ @WorkerThread - public static void refreshCapabilitiesIfNecessary(@NonNull Collection resolved) throws IOException { + public static boolean refreshCapabilitiesIfNecessary(@NonNull Collection resolved) throws IOException { Set needsRefresh = Stream.of(resolved) .filter(r -> r.getGroupsV2Capability() != Recipient.Capability.SUPPORTED) .map(Recipient::getId) @@ -48,6 +49,10 @@ public final class GroupsV2CapabilityChecker { throw new IOException("Recipient capability was not retrieved in time"); } } + + return true; + } else { + return false; } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java index 820301a9ff..e3ce9a5fbd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/ui/creategroup/CreateGroupActivity.java @@ -39,7 +39,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.function.Consumer; +import java.util.stream.Collectors; public class CreateGroupActivity extends ContactSelectionActivity { @@ -164,17 +166,18 @@ public class CreateGroupActivity extends ContactSelectionActivity { SimpleProgressDialog.DismissibleDialog dismissibleDialog = SimpleProgressDialog.showDelayed(this); SimpleTask.run(getLifecycle(), () -> { - List ids = Stream.of(contactsFragment.getSelectedContacts()) - .map(selectedContact -> selectedContact.getOrCreateRecipientId(this)) - .toList(); + List ids = contactsFragment.getSelectedContacts() + .stream() + .map(selectedContact -> selectedContact.getOrCreateRecipientId(this)) + .collect(Collectors.toList()); List resolved = Recipient.resolvedList(ids); stopwatch.split("resolve"); - List registeredChecks = Stream.of(resolved) - .filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN) - .toList(); + Set registeredChecks = resolved.stream() + .filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN) + .collect(Collectors.toSet()); 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"); List recipientsAndSelf = new ArrayList<>(resolved); recipientsAndSelf.add(Recipient.self().resolve()); + boolean neededRefresh = false; + if (!SignalStore.internalValues().gv2DoNotCreateGv2Groups()) { try { - GroupsV2CapabilityChecker.refreshCapabilitiesIfNecessary(recipientsAndSelf); + neededRefresh = GroupsV2CapabilityChecker.refreshCapabilitiesIfNecessary(recipientsAndSelf); } catch (IOException e) { Log.w(TAG, "Failed to refresh all recipient capabilities.", e); } } + if (neededRefresh) { + resolved = Recipient.resolvedList(ids); + } + stopwatch.split("capabilities"); - resolved = Recipient.resolvedList(ids); Pair> result;