Inline CDS feature flag.
This commit is contained in:
parent
41b10630bb
commit
f182be2d79
8 changed files with 22 additions and 111 deletions
|
@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||||
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
import org.thoughtcrime.securesms.util.views.SimpleProgressDialog;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
@ -65,16 +66,17 @@ public class NewConversationActivity extends ContactSelectionActivity
|
||||||
launch(Recipient.resolved(recipientId.get()));
|
launch(Recipient.resolved(recipientId.get()));
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "[onContactSelected] Maybe creating a new recipient.");
|
Log.i(TAG, "[onContactSelected] Maybe creating a new recipient.");
|
||||||
if (FeatureFlags.cds() && NetworkConstraint.isMet(this)) {
|
|
||||||
Log.i(TAG, "[onContactSelected] CDS enabled. Doing contact refresh.");
|
if (TextSecurePreferences.isPushRegistered(this) && NetworkConstraint.isMet(this)) {
|
||||||
|
Log.i(TAG, "[onContactSelected] Doing contact refresh.");
|
||||||
|
|
||||||
AlertDialog progress = SimpleProgressDialog.show(this);
|
AlertDialog progress = SimpleProgressDialog.show(this);
|
||||||
|
|
||||||
SimpleTask.run(getLifecycle(), () -> {
|
SimpleTask.run(getLifecycle(), () -> {
|
||||||
Recipient resolved = Recipient.external(this, number);
|
Recipient resolved = Recipient.external(this, number);
|
||||||
|
|
||||||
if (!resolved.isRegistered()) {
|
if (!resolved.isRegistered() || !resolved.hasUuid()) {
|
||||||
Log.i(TAG, "[onContactSelected] Not registered. Doing a directory refresh.");
|
Log.i(TAG, "[onContactSelected] Not registered or no UUID. Doing a directory refresh.");
|
||||||
try {
|
try {
|
||||||
DirectoryHelper.refreshDirectoryFor(this, resolved, false);
|
DirectoryHelper.refreshDirectoryFor(this, resolved, false);
|
||||||
resolved = Recipient.resolved(resolved.getId());
|
resolved = Recipient.resolved(resolved.getId());
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
package org.thoughtcrime.securesms.contacts.sync;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.annimon.stream.Collectors;
|
|
||||||
import com.annimon.stream.Stream;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper.DirectoryResult;
|
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
|
||||||
import org.thoughtcrime.securesms.util.SetUtil;
|
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
|
||||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
|
||||||
import org.whispersystems.signalservice.api.push.ContactTokenDetails;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
class ContactDiscoveryV1 {
|
|
||||||
|
|
||||||
private static final String TAG = ContactDiscoveryV1.class.getSimpleName();
|
|
||||||
|
|
||||||
static @NonNull DirectoryResult getDirectoryResult(@NonNull Set<String> databaseNumbers,
|
|
||||||
@NonNull Set<String> systemNumbers)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
Set<String> allNumbers = SetUtil.union(databaseNumbers, systemNumbers);
|
|
||||||
FuzzyPhoneNumberHelper.InputResult inputResult = FuzzyPhoneNumberHelper.generateInput(allNumbers, databaseNumbers);
|
|
||||||
List<ContactTokenDetails> activeTokens = getTokens(inputResult.getNumbers());
|
|
||||||
Set<String> activeNumbers = Stream.of(activeTokens).map(ContactTokenDetails::getNumber).collect(Collectors.toSet());
|
|
||||||
FuzzyPhoneNumberHelper.OutputResult outputResult = FuzzyPhoneNumberHelper.generateOutput(activeNumbers, inputResult);
|
|
||||||
HashMap<String, UUID> uuids = new HashMap<>();
|
|
||||||
|
|
||||||
for (String number : outputResult.getNumbers()) {
|
|
||||||
uuids.put(number, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DirectoryResult(uuids, outputResult.getRewrites());
|
|
||||||
}
|
|
||||||
|
|
||||||
static @NonNull DirectoryResult getDirectoryResult(@NonNull String number) throws IOException {
|
|
||||||
return getDirectoryResult(Collections.singleton(number), Collections.singleton(number));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static @NonNull List<ContactTokenDetails> getTokens(@NonNull Set<String> numbers) throws IOException {
|
|
||||||
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
|
|
||||||
|
|
||||||
if (numbers.size() == 1) {
|
|
||||||
Optional<ContactTokenDetails> details = accountManager.getContact(numbers.iterator().next());
|
|
||||||
return details.isPresent() ? Collections.singletonList(details.get()) : Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
return accountManager.getContacts(numbers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -31,6 +31,9 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses CDS to map E164's to UUIDs.
|
||||||
|
*/
|
||||||
class ContactDiscoveryV2 {
|
class ContactDiscoveryV2 {
|
||||||
|
|
||||||
private static final String TAG = Log.tag(ContactDiscoveryV2.class);
|
private static final String TAG = Log.tag(ContactDiscoveryV2.class);
|
||||||
|
|
|
@ -158,13 +158,7 @@ public class DirectoryHelper {
|
||||||
return RegisteredState.NOT_REGISTERED;
|
return RegisteredState.NOT_REGISTERED;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectoryResult result;
|
DirectoryResult result = ContactDiscoveryV2.getDirectoryResult(context, recipient.getE164().get());
|
||||||
|
|
||||||
if (FeatureFlags.cds()) {
|
|
||||||
result = ContactDiscoveryV2.getDirectoryResult(context, recipient.getE164().get());
|
|
||||||
} else {
|
|
||||||
result = ContactDiscoveryV1.getDirectoryResult(recipient.getE164().get());
|
|
||||||
}
|
|
||||||
|
|
||||||
stopwatch.split("e164-network");
|
stopwatch.split("e164-network");
|
||||||
|
|
||||||
|
@ -229,13 +223,7 @@ public class DirectoryHelper {
|
||||||
|
|
||||||
Stopwatch stopwatch = new Stopwatch("refresh");
|
Stopwatch stopwatch = new Stopwatch("refresh");
|
||||||
|
|
||||||
DirectoryResult result;
|
DirectoryResult result = ContactDiscoveryV2.getDirectoryResult(context, databaseNumbers, systemNumbers);
|
||||||
|
|
||||||
if (FeatureFlags.cds()) {
|
|
||||||
result = ContactDiscoveryV2.getDirectoryResult(context, databaseNumbers, systemNumbers);
|
|
||||||
} else {
|
|
||||||
result = ContactDiscoveryV1.getDirectoryResult(databaseNumbers, systemNumbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
stopwatch.split("network");
|
stopwatch.split("network");
|
||||||
|
|
||||||
|
|
|
@ -394,10 +394,6 @@ public class RecipientDatabase extends Database {
|
||||||
throw new IllegalArgumentException("Must provide a UUID or E164!");
|
throw new IllegalArgumentException("Must provide a UUID or E164!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FeatureFlags.cds()) {
|
|
||||||
highTrust = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
RecipientId recipientNeedingRefresh = null;
|
RecipientId recipientNeedingRefresh = null;
|
||||||
Pair<RecipientId, RecipientId> remapped = null;
|
Pair<RecipientId, RecipientId> remapped = null;
|
||||||
boolean transactionSuccessful = false;
|
boolean transactionSuccessful = false;
|
||||||
|
|
|
@ -78,13 +78,7 @@ public final class PushGroupSilentUpdateSendJob extends BaseJob {
|
||||||
.filter(uuid -> !UuidUtil.UNKNOWN_UUID.equals(uuid))
|
.filter(uuid -> !UuidUtil.UNKNOWN_UUID.equals(uuid))
|
||||||
.filter(uuid -> !Recipient.self().getUuid().get().equals(uuid))
|
.filter(uuid -> !Recipient.self().getUuid().get().equals(uuid))
|
||||||
.map(uuid -> Recipient.externalPush(context, uuid, null, false))
|
.map(uuid -> Recipient.externalPush(context, uuid, null, false))
|
||||||
.filter(recipient -> {
|
.filter(recipient -> recipient.getRegistered() != RecipientDatabase.RegisteredState.NOT_REGISTERED)
|
||||||
if (FeatureFlags.cds()) {
|
|
||||||
return recipient.getRegistered() != RecipientDatabase.RegisteredState.NOT_REGISTERED;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(Recipient::getId)
|
.map(Recipient::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class RecipientUtil {
|
||||||
throw new AssertionError(recipient.getId() + " - No UUID or phone number!");
|
throw new AssertionError(recipient.getId() + " - No UUID or phone number!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FeatureFlags.cds() && !recipient.getUuid().isPresent()) {
|
if (!recipient.getUuid().isPresent()) {
|
||||||
Log.i(TAG, recipient.getId() + " is missing a UUID...");
|
Log.i(TAG, recipient.getId() + " is missing a UUID...");
|
||||||
RegisteredState state = DirectoryHelper.refreshDirectoryFor(context, recipient, false);
|
RegisteredState state = DirectoryHelper.refreshDirectoryFor(context, recipient, false);
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ public class RecipientUtil {
|
||||||
public static void ensureUuidsAreAvailable(@NonNull Context context, @NonNull Collection<Recipient> recipients)
|
public static void ensureUuidsAreAvailable(@NonNull Context context, @NonNull Collection<Recipient> recipients)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
if (FeatureFlags.cds()) {
|
|
||||||
List<Recipient> recipientsWithoutUuids = Stream.of(recipients)
|
List<Recipient> recipientsWithoutUuids = Stream.of(recipients)
|
||||||
.map(Recipient::resolve)
|
.map(Recipient::resolve)
|
||||||
.filterNot(Recipient::hasUuid)
|
.filterNot(Recipient::hasUuid)
|
||||||
|
@ -107,7 +106,6 @@ public class RecipientUtil {
|
||||||
DirectoryHelper.refreshDirectoryFor(context, recipientsWithoutUuids, false);
|
DirectoryHelper.refreshDirectoryFor(context, recipientsWithoutUuids, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBlockable(@NonNull Recipient recipient) {
|
public static boolean isBlockable(@NonNull Recipient recipient) {
|
||||||
Recipient resolved = recipient.resolve();
|
Recipient resolved = recipient.resolve();
|
||||||
|
@ -115,13 +113,9 @@ public class RecipientUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Recipient> getEligibleForSending(@NonNull List<Recipient> recipients) {
|
public static List<Recipient> getEligibleForSending(@NonNull List<Recipient> recipients) {
|
||||||
if (FeatureFlags.cds()) {
|
|
||||||
return Stream.of(recipients)
|
return Stream.of(recipients)
|
||||||
.filter(r -> r.getRegistered() != RegisteredState.NOT_REGISTERED)
|
.filter(r -> r.getRegistered() != RegisteredState.NOT_REGISTERED)
|
||||||
.toList();
|
.toList();
|
||||||
} else {
|
|
||||||
return recipients;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,7 +53,6 @@ public final class FeatureFlags {
|
||||||
private static final String GROUPS_V2_JOIN_VERSION = "android.groupsv2.joinVersion";
|
private static final String GROUPS_V2_JOIN_VERSION = "android.groupsv2.joinVersion";
|
||||||
private static final String GROUPS_V2_LINKS_VERSION = "android.groupsv2.manageGroupLinksVersion";
|
private static final String GROUPS_V2_LINKS_VERSION = "android.groupsv2.manageGroupLinksVersion";
|
||||||
private static final String GROUPS_V2_CAPACITY = "global.groupsv2.maxGroupSize";
|
private static final String GROUPS_V2_CAPACITY = "global.groupsv2.maxGroupSize";
|
||||||
private static final String CDS_VERSION = "android.cdsVersion";
|
|
||||||
private static final String INTERNAL_USER = "android.internalUser";
|
private static final String INTERNAL_USER = "android.internalUser";
|
||||||
private static final String MENTIONS = "android.mentions";
|
private static final String MENTIONS = "android.mentions";
|
||||||
private static final String VERIFY_V2 = "android.verifyV2";
|
private static final String VERIFY_V2 = "android.verifyV2";
|
||||||
|
@ -72,7 +71,6 @@ public final class FeatureFlags {
|
||||||
GROUPS_V2_CAPACITY,
|
GROUPS_V2_CAPACITY,
|
||||||
GROUPS_V2_JOIN_VERSION,
|
GROUPS_V2_JOIN_VERSION,
|
||||||
GROUPS_V2_LINKS_VERSION,
|
GROUPS_V2_LINKS_VERSION,
|
||||||
CDS_VERSION,
|
|
||||||
INTERNAL_USER,
|
INTERNAL_USER,
|
||||||
USERNAMES,
|
USERNAMES,
|
||||||
MENTIONS,
|
MENTIONS,
|
||||||
|
@ -102,7 +100,6 @@ public final class FeatureFlags {
|
||||||
GROUPS_V2_CREATE_VERSION,
|
GROUPS_V2_CREATE_VERSION,
|
||||||
GROUPS_V2_JOIN_VERSION,
|
GROUPS_V2_JOIN_VERSION,
|
||||||
VERIFY_V2,
|
VERIFY_V2,
|
||||||
CDS_VERSION,
|
|
||||||
CLIENT_EXPIRATION
|
CLIENT_EXPIRATION
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -230,11 +227,6 @@ public final class FeatureFlags {
|
||||||
return getBoolean(INTERNAL_USER, false);
|
return getBoolean(INTERNAL_USER, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether or not to use the new contact discovery service endpoint, which supports UUIDs. */
|
|
||||||
public static boolean cds() {
|
|
||||||
return getVersionFlag(CDS_VERSION) == VersionFlag.ON;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Whether or not we allow mentions send support in groups. */
|
/** Whether or not we allow mentions send support in groups. */
|
||||||
public static boolean mentions() {
|
public static boolean mentions() {
|
||||||
return getBoolean(MENTIONS, false);
|
return getBoolean(MENTIONS, false);
|
||||||
|
|
Loading…
Add table
Reference in a new issue