mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Do not attempt to send to unregistered users when using CDS flag.
CDS is slow, and unregistered users will always trigger a CDS lookup on send (since we can't get their UUID). This starts skipping sends to unregistered users and shortens the time window to do a full CDS lookup from every 12 hours to every 6 hours.
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.android.gms.common.Feature;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
@@ -29,6 +30,7 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class RecipientUtil {
|
||||
@@ -38,7 +40,8 @@ public class RecipientUtil {
|
||||
/**
|
||||
* This method will do it's best to craft a fully-populated {@link SignalServiceAddress} based on
|
||||
* the provided recipient. This includes performing a possible network request if no UUID is
|
||||
* available.
|
||||
* available. If the request to get a UUID fails, the exception is swallowed an an E164-only
|
||||
* recipient is returned.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static @NonNull SignalServiceAddress toSignalServiceAddressBestEffort(@NonNull Context context, @NonNull Recipient recipient) {
|
||||
@@ -53,7 +56,7 @@ public class RecipientUtil {
|
||||
/**
|
||||
* This method will do it's best to craft a fully-populated {@link SignalServiceAddress} based on
|
||||
* the provided recipient. This includes performing a possible network request if no UUID is
|
||||
* available.
|
||||
* available. If the request to get a UUID fails, an IOException is thrown.
|
||||
*/
|
||||
@WorkerThread
|
||||
public static @NonNull SignalServiceAddress toSignalServiceAddress(@NonNull Context context, @NonNull Recipient recipient)
|
||||
@@ -79,25 +82,27 @@ public class RecipientUtil {
|
||||
public static @NonNull List<SignalServiceAddress> toSignalServiceAddresses(@NonNull Context context, @NonNull List<RecipientId> recipients)
|
||||
throws IOException
|
||||
{
|
||||
List<SignalServiceAddress> addresses = new ArrayList<>(recipients.size());
|
||||
|
||||
for (RecipientId id : recipients) {
|
||||
addresses.add(toSignalServiceAddress(context, Recipient.resolved(id)));
|
||||
}
|
||||
|
||||
return addresses;
|
||||
return toSignalServiceAddressesFromResolved(context, Recipient.resolvedList(recipients));
|
||||
}
|
||||
|
||||
public static @NonNull List<SignalServiceAddress> toSignalServiceAddressesFromResolved(@NonNull Context context, @NonNull List<Recipient> recipients)
|
||||
throws IOException
|
||||
{
|
||||
List<SignalServiceAddress> addresses = new ArrayList<>(recipients.size());
|
||||
if (FeatureFlags.cds()) {
|
||||
List<Recipient> recipientsWithoutUuids = Stream.of(recipients)
|
||||
.map(Recipient::resolve)
|
||||
.filterNot(Recipient::hasUuid)
|
||||
.toList();
|
||||
|
||||
for (Recipient recipient : recipients) {
|
||||
addresses.add(toSignalServiceAddress(context, recipient));
|
||||
if (recipientsWithoutUuids.size() > 0) {
|
||||
DirectoryHelper.refreshDirectoryFor(context, recipientsWithoutUuids, false);
|
||||
}
|
||||
}
|
||||
|
||||
return addresses;
|
||||
return Stream.of(recipients)
|
||||
.map(Recipient::resolve)
|
||||
.map(r -> new SignalServiceAddress(r.getUuid().orNull(), r.getE164().orNull()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static boolean isBlockable(@NonNull Recipient recipient) {
|
||||
@@ -105,6 +110,16 @@ public class RecipientUtil {
|
||||
return resolved.isPushGroup() || resolved.hasServiceIdentifier();
|
||||
}
|
||||
|
||||
public static List<Recipient> getEligibleForSending(@NonNull List<Recipient> recipients) {
|
||||
if (FeatureFlags.cds()) {
|
||||
return Stream.of(recipients)
|
||||
.filter(r -> r.getRegistered() != RegisteredState.NOT_REGISTERED)
|
||||
.toList();
|
||||
} else {
|
||||
return recipients;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* You can call this for non-groups and not have to handle any network errors.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user