Move from ACI to a generic ServiceId.

This commit is contained in:
Greyson Parrelli
2022-02-17 15:55:54 -05:00
parent 9f1deda220
commit 7ca2420287
110 changed files with 841 additions and 824 deletions

View File

@@ -23,7 +23,7 @@ public final class BucketingUtil {
* Calculate a user bucket for a given feature flag, uuid, and part per modulus.
*
* @param key Feature flag key (e.g., "research.megaphone.1")
* @param uuid Current user's UUID (see {@link Recipient#getAci()})
* @param uuid Current user's UUID (see {@link Recipient#getServiceId()})
* @param modulus Drives the bucketing parts per N (e.g., passing 1,000,000 indicates bucketing into parts per million)
*/
public static long bucket(@NonNull String key, @NonNull UUID uuid, long modulus) {

View File

@@ -240,7 +240,7 @@ public class CommunicationActions {
SimpleTask.run(() -> {
Recipient recipient = Recipient.external(activity, e164);
if (!recipient.isRegistered() || !recipient.hasAci()) {
if (!recipient.isRegistered() || !recipient.hasServiceId()) {
try {
DirectoryHelper.refreshDirectoryFor(activity, recipient, false);
recipient = Recipient.resolved(recipient.getId());

View File

@@ -161,7 +161,7 @@ public final class IdentityUtil {
public static void processVerifiedMessage(Context context, VerifiedMessage verifiedMessage) {
try(SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
SignalIdentityKeyStore identityStore = ApplicationDependencies.getProtocolStore().aci().identities();
Recipient recipient = Recipient.externalPush(context, verifiedMessage.getDestination());
Recipient recipient = Recipient.externalPush(verifiedMessage.getDestination());
Optional<IdentityRecord> identityRecord = identityStore.getIdentityRecord(recipient.getId());
if (!identityRecord.isPresent() && verifiedMessage.getVerified() == VerifiedMessage.VerifiedState.DEFAULT) {

View File

@@ -76,12 +76,12 @@ public final class LocaleFeatureFlags {
Map<String, Integer> countryCodeValues = parseCountryValues(serialized, 0);
Recipient self = Recipient.self();
if (countryCodeValues.isEmpty() || !self.getE164().isPresent() || !self.getAci().isPresent()) {
if (countryCodeValues.isEmpty() || !self.getE164().isPresent() || !self.getServiceId().isPresent()) {
return false;
}
long countEnabled = getCountryValue(countryCodeValues, self.getE164().or(""), 0);
long currentUserBucket = BucketingUtil.bucket(flag, self.requireAci().uuid(), 1_000_000);
long currentUserBucket = BucketingUtil.bucket(flag, self.requireServiceId().uuid(), 1_000_000);
return countEnabled > currentUserBucket;
}

View File

@@ -10,7 +10,6 @@ import org.signal.core.util.logging.Log;
import org.signal.zkgroup.InvalidInputException;
import org.signal.zkgroup.profiles.ProfileKey;
import org.thoughtcrime.securesms.badges.models.Badge;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
import org.thoughtcrime.securesms.database.RecipientDatabase;
@@ -284,7 +283,7 @@ public final class ProfileUtil {
ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
String avatarPath = accountManager.setVersionedProfile(Recipient.self().requireAci(),
String avatarPath = accountManager.setVersionedProfile(SignalStore.account().requireAci(),
profileKey,
profileName.serialize(),
about,
@@ -321,8 +320,8 @@ public final class ProfileUtil {
private static @NonNull SignalServiceAddress toSignalServiceAddress(@NonNull Context context, @NonNull Recipient recipient) throws IOException {
if (recipient.getRegistered() == RecipientDatabase.RegisteredState.NOT_REGISTERED) {
if (recipient.hasAci()) {
return new SignalServiceAddress(recipient.requireAci(), recipient.getE164().orNull());
if (recipient.hasServiceId()) {
return new SignalServiceAddress(recipient.requireServiceId(), recipient.getE164().orNull());
} else {
throw new IOException(recipient.getId() + " not registered!");
}

View File

@@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.util
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientId
import org.whispersystems.signalservice.api.push.ACI
import org.whispersystems.signalservice.api.push.ServiceId
import org.whispersystems.signalservice.api.push.SignalServiceAddress
/**
@@ -11,10 +11,10 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress
*/
class RecipientAccessList(private val recipients: List<Recipient>) : List<Recipient> by recipients {
private val byAci: Map<ACI, Recipient> by lazy {
private val byServiceId: Map<ServiceId, Recipient> by lazy {
recipients
.filter { it.hasAci() }
.associateBy { it.requireAci() }
.filter { it.hasServiceId() }
.associateBy { it.requireServiceId() }
}
private val byE164: Map<String, Recipient> by lazy {
@@ -24,8 +24,8 @@ class RecipientAccessList(private val recipients: List<Recipient>) : List<Recipi
}
fun requireByAddress(address: SignalServiceAddress): Recipient {
if (byAci.containsKey(address.aci)) {
return byAci[address.aci]!!
if (byServiceId.containsKey(address.serviceId)) {
return byServiceId[address.serviceId]!!
} else if (address.number.isPresent && byE164.containsKey(address.number.get())) {
return byE164[address.number.get()]!!
} else {

View File

@@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.profiles.SignalServiceProfile;
import org.whispersystems.signalservice.api.push.ACI;
import org.whispersystems.signalservice.api.push.ServiceId;
import java.io.IOException;
import java.util.Locale;
@@ -51,15 +52,15 @@ public class UsernameUtil {
}
@WorkerThread
public static @NonNull Optional<ACI> fetchAciForUsername(@NonNull Context context, @NonNull String username) {
public static @NonNull Optional<ServiceId> fetchAciForUsername(@NonNull String username) {
Optional<RecipientId> localId = SignalDatabase.recipients().getByUsername(username);
if (localId.isPresent()) {
Recipient recipient = Recipient.resolved(localId.get());
if (recipient.getAci().isPresent()) {
if (recipient.getServiceId().isPresent()) {
Log.i(TAG, "Found username locally -- using associated UUID.");
return recipient.getAci();
return recipient.getServiceId();
} else {
Log.w(TAG, "Found username locally, but it had no associated UUID! Clearing it.");
SignalDatabase.recipients().clearUsernameIfExists(username);