getRecipientTrustedResolver().resolveSelfRecipientTrusted(getSelfRecipientAddress());
this.password = password;
this.profileKey = profileKey;
- getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
this.encryptedDeviceName = encryptedDeviceName;
this.aciAccountData.setIdentityKeyPair(aciIdentity);
this.pniAccountData.setIdentityKeyPair(pniIdentity);
// Old config file, creating new profile key
setProfileKey(KeyUtils.createProfileKey());
}
- getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
if (previousStorageVersion < 5) {
final var legacyRecipientsStoreFile = new File(userPath, "recipients-store");
if (legacyRecipientsStoreFile.exists()) {
LegacyRecipientStore2.migrate(legacyRecipientsStoreFile, getRecipientStore());
- // Ensure our profile key is stored in profile store
- getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
}
}
if (previousStorageVersion < 6) {
}
public RecipientStore getRecipientStore() {
- return getOrCreate(() -> recipientStore, () -> {
- recipientStore = new RecipientStore(this::mergeRecipients,
- this::getSelfRecipientAddress,
- getAccountDatabase());
- getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
- });
+ return getOrCreate(() -> recipientStore,
+ () -> recipientStore = new RecipientStore(this::mergeRecipients,
+ this::getSelfRecipientAddress,
+ this::getProfileKey,
+ getAccountDatabase()));
}
public ProfileStore getProfileStore() {
}
this.profileKey = profileKey;
save();
- getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
}
public byte[] getSelfUnidentifiedAccessKey() {
private final RecipientMergeHandler recipientMergeHandler;
private final SelfAddressProvider selfAddressProvider;
+ private final SelfProfileKeyProvider selfProfileKeyProvider;
private final Database database;
private final Object recipientsLock = new Object();
public RecipientStore(
final RecipientMergeHandler recipientMergeHandler,
final SelfAddressProvider selfAddressProvider,
+ final SelfProfileKeyProvider selfProfileKeyProvider,
final Database database
) {
this.recipientMergeHandler = recipientMergeHandler;
this.selfAddressProvider = selfAddressProvider;
+ this.selfProfileKeyProvider = selfProfileKeyProvider;
this.database = database;
}
WHERE (r.number IS NOT NULL OR r.uuid IS NOT NULL) AND %s
"""
).formatted(TABLE_RECIPIENT, sqlWhere.isEmpty() ? "TRUE" : String.join(" AND ", sqlWhere));
+ final var selfServiceId = selfAddressProvider.getSelfAddress().serviceId();
try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) {
if (blocked.isPresent()) {
try (var result = Utils.executeQueryForStream(statement, this::getRecipientFromResultSet)) {
return result.filter(r -> name.isEmpty() || (
r.getContact() != null && name.get().equals(r.getContact().getName())
- ) || (r.getProfile() != null && name.get().equals(r.getProfile().getDisplayName()))).toList();
+ ) || (r.getProfile() != null && name.get().equals(r.getProfile().getDisplayName()))).map(r -> {
+ if (r.getAddress().serviceId().equals(selfServiceId)) {
+ return Recipient.newBuilder(r)
+ .withProfileKey(selfProfileKeyProvider.getSelfProfileKey())
+ .build();
+ }
+ return r;
+ }).toList();
}
}
} catch (SQLException e) {
WHERE r.uuid IS NOT NULL AND r.profile_key IS NOT NULL
"""
).formatted(TABLE_RECIPIENT);
+ final var selfServiceId = selfAddressProvider.getSelfAddress().serviceId().orElse(null);
try (final var connection = database.getConnection()) {
try (final var statement = connection.prepareStatement(sql)) {
return Utils.executeQueryForStream(statement, resultSet -> {
final var serviceId = ServiceId.parseOrThrow(resultSet.getBytes("uuid"));
+ if (serviceId.equals(selfServiceId)) {
+ return new Pair<>(serviceId, selfProfileKeyProvider.getSelfProfileKey());
+ }
final var profileKey = getProfileKeyFromResultSet(resultSet);
return new Pair<>(serviceId, profileKey);
}).filter(Objects::nonNull).collect(Collectors.toMap(Pair::first, Pair::second));
@Override
public ProfileKey getProfileKey(final RecipientId recipientId) {
+ final var selfRecipientId = resolveRecipient(selfAddressProvider.getSelfAddress());
+ if (recipientId.equals(selfRecipientId)) {
+ return selfProfileKeyProvider.getSelfProfileKey();
+ }
try (final var connection = database.getConnection()) {
return getProfileKey(connection, recipientId);
} catch (SQLException e) {
}
}
- @Override
- public void storeSelfProfileKey(final RecipientId recipientId, final ProfileKey profileKey) {
- try (final var connection = database.getConnection()) {
- storeProfileKey(connection, recipientId, profileKey, false);
- } catch (SQLException e) {
- throw new RuntimeException("Failed update recipient store", e);
- }
- }
-
@Override
public void storeProfileKey(RecipientId recipientId, final ProfileKey profileKey) {
try (final var connection = database.getConnection()) {