mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Split contact name field in given name and family name
This commit is contained in:
parent
69e952738b
commit
5b1c6c0d64
7 changed files with 58 additions and 16 deletions
|
@ -20,7 +20,7 @@ public class ContactHelper {
|
||||||
public void setContactName(final RecipientId recipientId, final String name) {
|
public void setContactName(final RecipientId recipientId, final String name) {
|
||||||
var contact = account.getContactStore().getContact(recipientId);
|
var contact = account.getContactStore().getContact(recipientId);
|
||||||
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
||||||
account.getContactStore().storeContact(recipientId, builder.withName(name).build());
|
account.getContactStore().storeContact(recipientId, builder.withGivenName(name).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpirationTimer(RecipientId recipientId, int messageExpirationTimer) {
|
public void setExpirationTimer(RecipientId recipientId, int messageExpirationTimer) {
|
||||||
|
|
|
@ -95,9 +95,9 @@ public class StorageHelper {
|
||||||
|| blocked != contactRecord.isBlocked()
|
|| blocked != contactRecord.isBlocked()
|
||||||
|| profileShared != contactRecord.isProfileSharingEnabled()) {
|
|| profileShared != contactRecord.isProfileSharingEnabled()) {
|
||||||
final var contactBuilder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
final var contactBuilder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
||||||
final var name = contactRecord.getGivenName().orElse("") + " " + contactRecord.getFamilyName().orElse("");
|
|
||||||
final var newContact = contactBuilder.withBlocked(contactRecord.isBlocked())
|
final var newContact = contactBuilder.withBlocked(contactRecord.isBlocked())
|
||||||
.withName(name.trim())
|
.withGivenName(contactRecord.getGivenName().orElse(null))
|
||||||
|
.withFamilyName(contactRecord.getFamilyName().orElse(null))
|
||||||
.withProfileSharingEnabled(contactRecord.isProfileSharingEnabled())
|
.withProfileSharingEnabled(contactRecord.isProfileSharingEnabled())
|
||||||
.build();
|
.build();
|
||||||
account.getContactStore().storeContact(recipientId, newContact);
|
account.getContactStore().storeContact(recipientId, newContact);
|
||||||
|
|
|
@ -261,7 +261,7 @@ public class SyncHelper {
|
||||||
var contact = account.getContactStore().getContact(recipientId);
|
var contact = account.getContactStore().getContact(recipientId);
|
||||||
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
final var builder = contact == null ? Contact.newBuilder() : Contact.newBuilder(contact);
|
||||||
if (c.getName().isPresent()) {
|
if (c.getName().isPresent()) {
|
||||||
builder.withName(c.getName().get());
|
builder.withGivenName(c.getName().get());
|
||||||
}
|
}
|
||||||
if (c.getColor().isPresent()) {
|
if (c.getColor().isPresent()) {
|
||||||
builder.withColor(c.getColor().get());
|
builder.withColor(c.getColor().get());
|
||||||
|
|
|
@ -717,6 +717,7 @@ public class SignalAccount implements Closeable {
|
||||||
final var recipientId = getRecipientStore().resolveRecipientTrusted(contact.getAddress());
|
final var recipientId = getRecipientStore().resolveRecipientTrusted(contact.getAddress());
|
||||||
getContactStore().storeContact(recipientId,
|
getContactStore().storeContact(recipientId,
|
||||||
new Contact(contact.name,
|
new Contact(contact.name,
|
||||||
|
null,
|
||||||
contact.color,
|
contact.color,
|
||||||
contact.messageExpirationTime,
|
contact.messageExpirationTime,
|
||||||
contact.blocked,
|
contact.blocked,
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package org.asamk.signal.manager.storage.recipients;
|
package org.asamk.signal.manager.storage.recipients;
|
||||||
|
|
||||||
|
import org.whispersystems.signalservice.internal.util.Util;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Contact {
|
public class Contact {
|
||||||
|
|
||||||
private final String name;
|
private final String givenName;
|
||||||
|
|
||||||
|
private final String familyName;
|
||||||
|
|
||||||
private final String color;
|
private final String color;
|
||||||
|
|
||||||
|
@ -17,14 +21,16 @@ public class Contact {
|
||||||
private final boolean profileSharingEnabled;
|
private final boolean profileSharingEnabled;
|
||||||
|
|
||||||
public Contact(
|
public Contact(
|
||||||
final String name,
|
final String givenName,
|
||||||
|
final String familyName,
|
||||||
final String color,
|
final String color,
|
||||||
final int messageExpirationTime,
|
final int messageExpirationTime,
|
||||||
final boolean blocked,
|
final boolean blocked,
|
||||||
final boolean archived,
|
final boolean archived,
|
||||||
final boolean profileSharingEnabled
|
final boolean profileSharingEnabled
|
||||||
) {
|
) {
|
||||||
this.name = name;
|
this.givenName = givenName;
|
||||||
|
this.familyName = familyName;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.messageExpirationTime = messageExpirationTime;
|
this.messageExpirationTime = messageExpirationTime;
|
||||||
this.blocked = blocked;
|
this.blocked = blocked;
|
||||||
|
@ -33,7 +39,8 @@ public class Contact {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Contact(final Builder builder) {
|
private Contact(final Builder builder) {
|
||||||
name = builder.name;
|
givenName = builder.givenName;
|
||||||
|
familyName = builder.familyName;
|
||||||
color = builder.color;
|
color = builder.color;
|
||||||
messageExpirationTime = builder.messageExpirationTime;
|
messageExpirationTime = builder.messageExpirationTime;
|
||||||
blocked = builder.blocked;
|
blocked = builder.blocked;
|
||||||
|
@ -47,7 +54,8 @@ public class Contact {
|
||||||
|
|
||||||
public static Builder newBuilder(final Contact copy) {
|
public static Builder newBuilder(final Contact copy) {
|
||||||
Builder builder = new Builder();
|
Builder builder = new Builder();
|
||||||
builder.name = copy.getName();
|
builder.givenName = copy.getGivenName();
|
||||||
|
builder.familyName = copy.getFamilyName();
|
||||||
builder.color = copy.getColor();
|
builder.color = copy.getColor();
|
||||||
builder.messageExpirationTime = copy.getMessageExpirationTime();
|
builder.messageExpirationTime = copy.getMessageExpirationTime();
|
||||||
builder.blocked = copy.isBlocked();
|
builder.blocked = copy.isBlocked();
|
||||||
|
@ -57,7 +65,26 @@ public class Contact {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
final var noGivenName = Util.isEmpty(givenName);
|
||||||
|
final var noFamilyName = Util.isEmpty(familyName);
|
||||||
|
|
||||||
|
if (noGivenName && noFamilyName) {
|
||||||
|
return "";
|
||||||
|
} else if (noGivenName) {
|
||||||
|
return familyName;
|
||||||
|
} else if (noFamilyName) {
|
||||||
|
return givenName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return givenName + " " + familyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGivenName() {
|
||||||
|
return givenName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFamilyName() {
|
||||||
|
return familyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
|
@ -89,18 +116,26 @@ public class Contact {
|
||||||
&& blocked == contact.blocked
|
&& blocked == contact.blocked
|
||||||
&& archived == contact.archived
|
&& archived == contact.archived
|
||||||
&& profileSharingEnabled == contact.profileSharingEnabled
|
&& profileSharingEnabled == contact.profileSharingEnabled
|
||||||
&& Objects.equals(name, contact.name)
|
&& Objects.equals(givenName, contact.givenName)
|
||||||
|
&& Objects.equals(familyName, contact.familyName)
|
||||||
&& Objects.equals(color, contact.color);
|
&& Objects.equals(color, contact.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(name, color, messageExpirationTime, blocked, archived, profileSharingEnabled);
|
return Objects.hash(givenName,
|
||||||
|
familyName,
|
||||||
|
color,
|
||||||
|
messageExpirationTime,
|
||||||
|
blocked,
|
||||||
|
archived,
|
||||||
|
profileSharingEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private String name;
|
private String givenName;
|
||||||
|
private String familyName;
|
||||||
private String color;
|
private String color;
|
||||||
private int messageExpirationTime;
|
private int messageExpirationTime;
|
||||||
private boolean blocked;
|
private boolean blocked;
|
||||||
|
@ -110,8 +145,13 @@ public class Contact {
|
||||||
private Builder() {
|
private Builder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withName(final String val) {
|
public Builder withGivenName(final String val) {
|
||||||
name = val;
|
givenName = val;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withFamilyName(final String val) {
|
||||||
|
familyName = val;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ public class RecipientStore implements RecipientResolver, RecipientTrustedResolv
|
||||||
Contact contact = null;
|
Contact contact = null;
|
||||||
if (r.contact != null) {
|
if (r.contact != null) {
|
||||||
contact = new Contact(r.contact.name,
|
contact = new Contact(r.contact.name,
|
||||||
|
null,
|
||||||
r.contact.color,
|
r.contact.color,
|
||||||
r.contact.messageExpirationTime,
|
r.contact.messageExpirationTime,
|
||||||
r.contact.blocked,
|
r.contact.blocked,
|
||||||
|
|
|
@ -574,7 +574,7 @@ public class DbusManagerImpl implements Manager {
|
||||||
}
|
}
|
||||||
return Recipient.newBuilder()
|
return Recipient.newBuilder()
|
||||||
.withAddress(new RecipientAddress(null, n))
|
.withAddress(new RecipientAddress(null, n))
|
||||||
.withContact(new Contact(contactName, null, 0, contactBlocked, false, false))
|
.withContact(new Contact(contactName, null, null, 0, contactBlocked, false, false))
|
||||||
.build();
|
.build();
|
||||||
}).filter(Objects::nonNull).toList();
|
}).filter(Objects::nonNull).toList();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue