Split given/family name in updateContact command

This commit is contained in:
AsamK 2022-05-29 22:21:24 +02:00
parent 27dbc671e0
commit badbb55ef2
7 changed files with 32 additions and 13 deletions

View file

@ -149,7 +149,7 @@ public interface Manager extends Closeable {
void deleteContact(RecipientIdentifier.Single recipient);
void setContactName(
RecipientIdentifier.Single recipient, String name
RecipientIdentifier.Single recipient, String givenName, final String familyName
) throws NotPrimaryDeviceException, IOException, UnregisteredRecipientException;
void setContactsBlocked(

View file

@ -705,12 +705,13 @@ class ManagerImpl implements Manager {
@Override
public void setContactName(
RecipientIdentifier.Single recipient, String name
RecipientIdentifier.Single recipient, String givenName, final String familyName
) throws NotPrimaryDeviceException, UnregisteredRecipientException {
if (!account.isPrimaryDevice()) {
throw new NotPrimaryDeviceException();
}
context.getContactHelper().setContactName(context.getRecipientHelper().resolveRecipient(recipient), name);
context.getContactHelper()
.setContactName(context.getRecipientHelper().resolveRecipient(recipient), givenName, familyName);
}
@Override

View file

@ -17,10 +17,16 @@ public class ContactHelper {
return sourceContact != null && sourceContact.isBlocked();
}
public void setContactName(final RecipientId recipientId, final String name) {
public void setContactName(final RecipientId recipientId, final String givenName, final String familyName) {
var contact = account.getContactStore().getContact(recipientId);
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
account.getContactStore().storeContact(recipientId, builder.withGivenName(name).build());
if (givenName != null) {
builder.withGivenName(givenName);
}
if (familyName != null) {
builder.withFamilyName(familyName);
}
account.getContactStore().storeContact(recipientId, builder.build());
}
public void setExpirationTimer(RecipientId recipientId, int messageExpirationTimer) {