Fix refresh issues when creating group with first-time contacts.
This commit is contained in:
parent
22c396067d
commit
6e71514209
2 changed files with 26 additions and 9 deletions
|
@ -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<Recipient> resolved) throws IOException {
|
||||
public static boolean refreshCapabilitiesIfNecessary(@NonNull Collection<Recipient> resolved) throws IOException {
|
||||
Set<RecipientId> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<RecipientId> ids = Stream.of(contactsFragment.getSelectedContacts())
|
||||
.map(selectedContact -> selectedContact.getOrCreateRecipientId(this))
|
||||
.toList();
|
||||
List<RecipientId> ids = contactsFragment.getSelectedContacts()
|
||||
.stream()
|
||||
.map(selectedContact -> selectedContact.getOrCreateRecipientId(this))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<Recipient> resolved = Recipient.resolvedList(ids);
|
||||
|
||||
stopwatch.split("resolve");
|
||||
|
||||
List<Recipient> registeredChecks = Stream.of(resolved)
|
||||
.filter(r -> r.getRegistered() == RecipientDatabase.RegisteredState.UNKNOWN)
|
||||
.toList();
|
||||
Set<Recipient> 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<Recipient> 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<Boolean, List<RecipientId>> result;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue