Add handling for new nickname and note fields

This commit is contained in:
AsamK 2024-04-12 16:57:20 +02:00
parent e5ebb732cb
commit e0cd5b987e
8 changed files with 56 additions and 1 deletions

View file

@ -6,6 +6,9 @@ public record Contact(
String givenName,
String familyName,
String nickName,
String nickNameGivenName,
String nickNameFamilyName,
String note,
String color,
int messageExpirationTime,
long muteUntil,
@ -21,6 +24,9 @@ public record Contact(
this(builder.givenName,
builder.familyName,
builder.nickName,
builder.nickNameGivenName,
builder.nickNameFamilyName,
builder.note,
builder.color,
builder.messageExpirationTime,
builder.muteUntil,
@ -73,6 +79,9 @@ public record Contact(
private String givenName;
private String familyName;
private String nickName;
private String nickNameGivenName;
private String nickNameFamilyName;
private String note;
private String color;
private int messageExpirationTime;
private long muteUntil;
@ -105,6 +114,21 @@ public record Contact(
return this;
}
public Builder withNickNameGivenName(final String val) {
nickNameGivenName = val;
return this;
}
public Builder withNickNameFamilyName(final String val) {
nickNameFamilyName = val;
return this;
}
public Builder withNote(final String val) {
note = val;
return this;
}
public Builder withColor(final String val) {
color = val;
return this;

View file

@ -33,7 +33,7 @@ import java.util.UUID;
public class AccountDatabase extends Database {
private static final Logger logger = LoggerFactory.getLogger(AccountDatabase.class);
private static final long DATABASE_VERSION = 24;
private static final long DATABASE_VERSION = 25;
private AccountDatabase(final HikariDataSource dataSource) {
super(logger, DATABASE_VERSION, dataSource);
@ -581,6 +581,16 @@ public class AccountDatabase extends Database {
""");
}
}
if (oldVersion < 25) {
logger.debug("Updating database: Create nick_name and note columns");
try (final var statement = connection.createStatement()) {
statement.executeUpdate("""
ALTER TABLE recipient ADD nick_name_given_name TEXT;
ALTER TABLE recipient ADD nick_name_family_name TEXT;
ALTER TABLE recipient ADD note TEXT;
""");
}
}
}
private static void createUuidMappingTable(

View file

@ -857,6 +857,9 @@ public class SignalAccount implements Closeable {
final var recipientId = getRecipientStore().resolveRecipientTrusted(contact.getAddress());
getContactStore().storeContact(recipientId,
new Contact(contact.name,
null,
null,
null,
null,
null,
contact.color,

View file

@ -39,6 +39,9 @@ public class LegacyRecipientStore2 {
Contact contact = null;
if (r.contact != null) {
contact = new Contact(r.contact.name,
null,
null,
null,
null,
null,
r.contact.color,

View file

@ -71,6 +71,9 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
given_name TEXT,
family_name TEXT,
nick_name TEXT,
nick_name_given_name TEXT,
nick_name_family_name TEXT,
note TEXT,
color TEXT,
expiration_time INTEGER NOT NULL DEFAULT 0,
@ -1436,6 +1439,9 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
return new Contact(resultSet.getString("given_name"),
resultSet.getString("family_name"),
resultSet.getString("nick_name"),
resultSet.getString("nick_name_given_name"),
resultSet.getString("nick_name_family_name"),
resultSet.getString("note"),
resultSet.getString("color"),
resultSet.getInt("expiration_time"),
resultSet.getLong("mute_until"),

View file

@ -271,6 +271,9 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
.withGivenName(contactRecord.getSystemGivenName().orElse(null))
.withFamilyName(contactRecord.getSystemFamilyName().orElse(null))
.withNickName(contactRecord.getSystemNickname().orElse(null))
.withNickNameGivenName(contactRecord.getNicknameGivenName().orElse(null))
.withNickNameFamilyName(contactRecord.getNicknameFamilyName().orElse(null))
.withNote(contactRecord.getNote().orElse(null))
.withUnregisteredTimestamp(contactRecord.getUnregisteredTimestamp() == 0
? null
: contactRecord.getUnregisteredTimestamp());

View file

@ -97,6 +97,9 @@ public final class StorageSyncModels {
builder.setSystemGivenName(recipient.getContact().givenName())
.setSystemFamilyName(recipient.getContact().familyName())
.setSystemNickname(recipient.getContact().nickName())
.setNicknameGivenName(recipient.getContact().nickNameGivenName())
.setNicknameFamilyName(recipient.getContact().nickNameFamilyName())
.setNote(recipient.getContact().note())
.setBlocked(recipient.getContact().isBlocked())
.setProfileSharingEnabled(recipient.getContact().isProfileSharingEnabled())
.setMuteUntil(recipient.getContact().muteUntil())