accountManager.setVersionedProfile(account.getUuid(),
account.getProfileKey(),
newProfile.getInternalServiceName(),
- newProfile.getAbout(),
- newProfile.getAboutEmoji(),
+ newProfile.getAbout() == null ? "" : newProfile.getAbout(),
+ newProfile.getAboutEmoji() == null ? "" : newProfile.getAboutEmoji(),
streamDetails);
}
ServiceConfig.AUTOMATIC_NETWORK_RETRY);
}
- public Profile getRecipientProfile(
- SignalServiceAddress address
- ) {
- return getRecipientProfile(resolveRecipient(address), false);
- }
-
public Profile getRecipientProfile(
RecipientId recipientId
) {
final var profile = profileAndCredential.getProfile();
try {
- account.getIdentityKeyStore()
+ var newIdentity = account.getIdentityKeyStore()
.saveIdentity(recipientId,
new IdentityKey(Base64.getDecoder().decode(profile.getIdentityKey())),
new Date());
+
+ if (newIdentity) {
+ account.getSessionStore().archiveSessions(recipientId);
+ }
} catch (InvalidKeyException ignored) {
logger.warn("Got invalid identity key in profile for {}",
resolveSignalServiceAddress(recipientId).getLegacyIdentifier());
public Pair<Long, List<SendMessageResult>> sendGroupMessageReaction(
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, GroupId groupId
) throws IOException, InvalidNumberException, NotAGroupMemberException, GroupNotFoundException {
+ var targetAuthorRecipientId = canonicalizeAndResolveRecipient(targetAuthor);
var reaction = new SignalServiceDataMessage.Reaction(emoji,
remove,
- canonicalizeAndResolveSignalServiceAddress(targetAuthor),
+ resolveSignalServiceAddress(targetAuthorRecipientId),
targetSentTimestamp);
final var messageBuilder = SignalServiceDataMessage.newBuilder().withReaction(reaction);
}
g = (GroupInfoV1) group;
- if (!g.isMember(resolveRecipient(recipient))) {
+ final var recipientId = resolveRecipient(recipient);
+ if (!g.isMember(recipientId)) {
throw new NotAGroupMemberException(groupId, g.name);
}
var messageBuilder = getGroupUpdateMessageBuilder(g);
// Send group message only to the recipient who requested it
- return sendMessage(messageBuilder, Set.of(resolveRecipient(recipient)));
+ return sendMessage(messageBuilder, Set.of(recipientId));
}
private SignalServiceDataMessage.Builder getGroupUpdateMessageBuilder(GroupInfoV1 g) throws AttachmentInvalidException {
public Pair<Long, List<SendMessageResult>> sendMessageReaction(
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, List<String> recipients
) throws IOException, InvalidNumberException {
+ var targetAuthorRecipientId = canonicalizeAndResolveRecipient(targetAuthor);
var reaction = new SignalServiceDataMessage.Reaction(emoji,
remove,
- canonicalizeAndResolveSignalServiceAddress(targetAuthor),
+ resolveSignalServiceAddress(targetAuthorRecipientId),
targetSentTimestamp);
final var messageBuilder = SignalServiceDataMessage.newBuilder().withReaction(reaction);
return sendMessage(messageBuilder, getSignalServiceAddresses(recipients));
return contact == null || contact.getName() == null ? "" : contact.getName();
}
- public void setContactName(String number, String name) throws InvalidNumberException {
+ public void setContactName(String number, String name) throws InvalidNumberException, NotMasterDeviceException {
+ if (!account.isMasterDevice()) {
+ throw new NotMasterDeviceException();
+ }
final var recipientId = canonicalizeAndResolveRecipient(number);
var contact = account.getContactStore().getContact(recipientId);
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
account.getContactStore().storeContact(recipientId, builder.withName(name).build());
}
- public void setContactBlocked(String number, boolean blocked) throws InvalidNumberException {
+ public void setContactBlocked(
+ String number, boolean blocked
+ ) throws InvalidNumberException, NotMasterDeviceException {
+ if (!account.isMasterDevice()) {
+ throw new NotMasterDeviceException();
+ }
setContactBlocked(canonicalizeAndResolveRecipient(number), blocked);
}
}
}
- void requestSyncGroups() throws IOException {
+ public void requestAllSyncData() throws IOException {
+ requestSyncGroups();
+ requestSyncContacts();
+ requestSyncBlocked();
+ requestSyncConfiguration();
+ requestSyncKeys();
+ }
+
+ private void requestSyncGroups() throws IOException {
var r = SignalServiceProtos.SyncMessage.Request.newBuilder()
.setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS)
.build();
}
}
- void requestSyncContacts() throws IOException {
+ private void requestSyncContacts() throws IOException {
var r = SignalServiceProtos.SyncMessage.Request.newBuilder()
.setType(SignalServiceProtos.SyncMessage.Request.Type.CONTACTS)
.build();
}
}
- void requestSyncBlocked() throws IOException {
+ private void requestSyncBlocked() throws IOException {
var r = SignalServiceProtos.SyncMessage.Request.newBuilder()
.setType(SignalServiceProtos.SyncMessage.Request.Type.BLOCKED)
.build();
}
}
- void requestSyncConfiguration() throws IOException {
+ private void requestSyncConfiguration() throws IOException {
var r = SignalServiceProtos.SyncMessage.Request.newBuilder()
.setType(SignalServiceProtos.SyncMessage.Request.Type.CONFIGURATION)
.build();
}
}
- void requestSyncKeys() throws IOException {
+ private void requestSyncKeys() throws IOException {
var r = SignalServiceProtos.SyncMessage.Request.newBuilder()
.setType(SignalServiceProtos.SyncMessage.Request.Type.KEYS)
.build();
final var addressesMissingUuid = new HashSet<SignalServiceAddress>();
for (var number : numbers) {
- final var resolvedAddress = canonicalizeAndResolveSignalServiceAddress(number);
+ final var resolvedAddress = resolveSignalServiceAddress(canonicalizeAndResolveRecipient(number));
if (resolvedAddress.getUuid().isPresent()) {
signalServiceAddresses.add(resolvedAddress);
} else {
for (var r : result) {
if (r.getIdentityFailure() != null) {
- account.getIdentityKeyStore().
- saveIdentity(resolveRecipient(r.getAddress()),
- r.getIdentityFailure().getIdentityKey(),
- new Date());
+ final var recipientId = resolveRecipient(r.getAddress());
+ final var newIdentity = account.getIdentityKeyStore()
+ .saveIdentity(recipientId, r.getIdentityFailure().getIdentityKey(), new Date());
+ if (newIdentity) {
+ account.getSessionStore().archiveSessions(recipientId);
+ }
}
}
final var expirationTime = contact != null ? contact.getMessageExpirationTime() : 0;
messageBuilder.withExpiration(expirationTime);
message = messageBuilder.build();
- results.add(sendMessage(resolveSignalServiceAddress(recipientId), message));
+ results.add(sendMessage(recipientId, message));
}
return new Pair<>(timestamp, results);
}
private SendMessageResult sendSelfMessage(SignalServiceDataMessage message) throws IOException {
var messageSender = createMessageSender();
- var recipient = account.getSelfAddress();
+ var recipientId = account.getSelfRecipientId();
- final var unidentifiedAccess = unidentifiedAccessHelper.getAccessFor(resolveRecipient(recipient));
+ final var unidentifiedAccess = unidentifiedAccessHelper.getAccessFor(recipientId);
+ var recipient = resolveSignalServiceAddress(recipientId);
var transcript = new SentTranscriptMessage(Optional.of(recipient),
message.getTimestamp(),
message,
}
private SendMessageResult sendMessage(
- SignalServiceAddress address, SignalServiceDataMessage message
+ RecipientId recipientId, SignalServiceDataMessage message
) throws IOException {
var messageSender = createMessageSender();
- final var recipientId = resolveRecipient(address);
+ final var address = resolveSignalServiceAddress(recipientId);
try {
try {
return messageSender.sendMessage(address, unidentifiedAccessHelper.getAccessFor(recipientId), message);
private void storeProfileKeysFromMembers(final DecryptedGroup group) {
for (var member : group.getMembersList()) {
- final var address = resolveRecipient(new SignalServiceAddress(UuidUtil.parseOrThrow(member.getUuid()
- .toByteArray()), null));
+ final var uuid = UuidUtil.parseOrThrow(member.getUuid().toByteArray());
+ final var recipientId = account.getRecipientStore().resolveRecipient(uuid);
try {
account.getProfileStore()
- .storeProfileKey(address, new ProfileKey(member.getProfileKey().toByteArray()));
+ .storeProfileKey(recipientId, new ProfileKey(member.getProfileKey().toByteArray()));
} catch (InvalidInputException ignored) {
}
}
content = decryptMessage(envelope);
} catch (org.whispersystems.libsignal.UntrustedIdentityException e) {
if (!envelope.hasSource()) {
- final var recipientId = resolveRecipient(((org.whispersystems.libsignal.UntrustedIdentityException) e)
- .getName());
+ final var identifier = ((org.whispersystems.libsignal.UntrustedIdentityException) e).getName();
+ final var recipientId = resolveRecipient(identifier);
try {
account.getMessageCache().replaceSender(cachedMessage, recipientId);
} catch (IOException ioException) {
}
if (cachedMessage[0] != null) {
if (exception instanceof org.whispersystems.libsignal.UntrustedIdentityException) {
- final var recipientId = resolveRecipient(((org.whispersystems.libsignal.UntrustedIdentityException) exception)
- .getName());
+ final var identifier = ((org.whispersystems.libsignal.UntrustedIdentityException) exception).getName();
+ final var recipientId = resolveRecipient(identifier);
queuedActions.add(new RetrieveProfileAction(recipientId));
if (!envelope.hasSource()) {
try {
theirIdentityKey);
}
- @Deprecated
- public SignalServiceAddress canonicalizeAndResolveSignalServiceAddress(String identifier) throws InvalidNumberException {
- var canonicalizedNumber = UuidUtil.isUuid(identifier)
- ? identifier
- : PhoneNumberFormatter.formatNumber(identifier, account.getUsername());
- return resolveSignalServiceAddress(canonicalizedNumber);
- }
-
@Deprecated
public SignalServiceAddress resolveSignalServiceAddress(String identifier) {
var address = Utils.getSignalServiceAddressFromIdentifier(identifier);