Store username aci link in recipient store

This commit is contained in:
AsamK 2023-10-17 14:58:15 +02:00
parent 733c14bbc8
commit 1addffe622
2 changed files with 9 additions and 19 deletions

View file

@ -229,7 +229,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
} }
public RecipientId resolveRecipientByUsername( public RecipientId resolveRecipientByUsername(
final String username, Supplier<ServiceId> serviceIdSupplier final String username, Supplier<ACI> aciSupplier
) throws UnregisteredRecipientException { ) throws UnregisteredRecipientException {
final Optional<RecipientWithAddress> byUsername; final Optional<RecipientWithAddress> byUsername;
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
@ -238,14 +238,14 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
throw new RuntimeException("Failed read from recipient store", e); throw new RuntimeException("Failed read from recipient store", e);
} }
if (byUsername.isEmpty() || byUsername.get().address().serviceId().isEmpty()) { if (byUsername.isEmpty() || byUsername.get().address().serviceId().isEmpty()) {
final var serviceId = serviceIdSupplier.get(); final var aci = aciSupplier.get();
if (serviceId == null) { if (aci == null) {
throw new UnregisteredRecipientException(new org.asamk.signal.manager.api.RecipientAddress(null, throw new UnregisteredRecipientException(new org.asamk.signal.manager.api.RecipientAddress(null,
null, null,
username)); username));
} }
return resolveRecipient(serviceId); return resolveRecipientTrusted(aci, username);
} }
return byUsername.get().id(); return byUsername.get().id();
} }
@ -287,17 +287,8 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
} }
@Override @Override
public RecipientId resolveRecipientTrusted(final ServiceId serviceId, final String username) { public RecipientId resolveRecipientTrusted(final ACI aci, final String username) {
return resolveRecipientTrusted(new RecipientAddress(serviceId, null, null, username), false); return resolveRecipientTrusted(new RecipientAddress(aci, null, null, username), false);
}
public RecipientId resolveRecipientTrusted(
final ACI aci, final String username
) {
return resolveRecipientTrusted(new RecipientAddress(Optional.of(aci),
Optional.empty(),
Optional.empty(),
Optional.of(username)), false);
} }
@Override @Override

View file

@ -1,6 +1,5 @@
package org.asamk.signal.manager.storage.recipients; package org.asamk.signal.manager.storage.recipients;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.ServiceId.ACI; import org.whispersystems.signalservice.api.push.ServiceId.ACI;
import org.whispersystems.signalservice.api.push.ServiceId.PNI; import org.whispersystems.signalservice.api.push.ServiceId.PNI;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -16,7 +15,7 @@ public interface RecipientTrustedResolver {
RecipientId resolveRecipientTrusted(Optional<ACI> aci, Optional<PNI> pni, Optional<String> number); RecipientId resolveRecipientTrusted(Optional<ACI> aci, Optional<PNI> pni, Optional<String> number);
RecipientId resolveRecipientTrusted(ServiceId serviceId, String username); RecipientId resolveRecipientTrusted(ACI aci, String username);
class RecipientTrustedResolverWrapper implements RecipientTrustedResolver { class RecipientTrustedResolverWrapper implements RecipientTrustedResolver {
@ -44,8 +43,8 @@ public interface RecipientTrustedResolver {
} }
@Override @Override
public RecipientId resolveRecipientTrusted(final ServiceId serviceId, final String username) { public RecipientId resolveRecipientTrusted(final ACI aci, final String username) {
return recipientTrustedResolverSupplier.get().resolveRecipientTrusted(serviceId, username); return recipientTrustedResolverSupplier.get().resolveRecipientTrusted(aci, username);
} }
} }
} }