mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Move aci/pni to account data object
This commit is contained in:
parent
889ef66784
commit
66161b74a6
1 changed files with 36 additions and 38 deletions
|
@ -127,8 +127,6 @@ public class SignalAccount implements Closeable {
|
||||||
private ServiceEnvironment serviceEnvironment;
|
private ServiceEnvironment serviceEnvironment;
|
||||||
private String number;
|
private String number;
|
||||||
private String username;
|
private String username;
|
||||||
private ACI aci;
|
|
||||||
private PNI pni;
|
|
||||||
private String encryptedDeviceName;
|
private String encryptedDeviceName;
|
||||||
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
||||||
private String password;
|
private String password;
|
||||||
|
@ -152,8 +150,8 @@ public class SignalAccount implements Closeable {
|
||||||
private boolean isMultiDevice = false;
|
private boolean isMultiDevice = false;
|
||||||
private boolean registered = false;
|
private boolean registered = false;
|
||||||
|
|
||||||
private final AccountData aciAccountData = new AccountData(ServiceIdType.ACI);
|
private final AccountData<ACI> aciAccountData = new AccountData<>(ServiceIdType.ACI);
|
||||||
private final AccountData pniAccountData = new AccountData(ServiceIdType.PNI);
|
private final AccountData<PNI> pniAccountData = new AccountData<>(ServiceIdType.PNI);
|
||||||
private IdentityKeyStore identityKeyStore;
|
private IdentityKeyStore identityKeyStore;
|
||||||
private SenderKeyStore senderKeyStore;
|
private SenderKeyStore senderKeyStore;
|
||||||
private GroupStore groupStore;
|
private GroupStore groupStore;
|
||||||
|
@ -352,8 +350,8 @@ public class SignalAccount implements Closeable {
|
||||||
final ProfileKey profileKey
|
final ProfileKey profileKey
|
||||||
) {
|
) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.aci = aci;
|
this.aciAccountData.setServiceId(aci);
|
||||||
this.pni = pni;
|
this.pniAccountData.setServiceId(pni);
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.profileKey = profileKey;
|
this.profileKey = profileKey;
|
||||||
getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
|
getProfileStore().storeSelfProfileKey(getSelfRecipientId(), getProfileKey());
|
||||||
|
@ -388,8 +386,8 @@ public class SignalAccount implements Closeable {
|
||||||
this.deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
this.deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
|
||||||
this.isMultiDevice = false;
|
this.isMultiDevice = false;
|
||||||
this.registered = true;
|
this.registered = true;
|
||||||
this.aci = aci;
|
this.aciAccountData.setServiceId(aci);
|
||||||
this.pni = pni;
|
this.pniAccountData.setServiceId(pni);
|
||||||
this.registrationLockPin = pin;
|
this.registrationLockPin = pin;
|
||||||
getKeyValueStore().storeEntry(lastReceiveTimestamp, 0L);
|
getKeyValueStore().storeEntry(lastReceiveTimestamp, 0L);
|
||||||
save();
|
save();
|
||||||
|
@ -558,14 +556,14 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
if (rootNode.hasNonNull("uuid")) {
|
if (rootNode.hasNonNull("uuid")) {
|
||||||
try {
|
try {
|
||||||
aci = ACI.parseOrThrow(rootNode.get("uuid").asText());
|
aciAccountData.setServiceId(ACI.parseOrThrow(rootNode.get("uuid").asText()));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IOException("Config file contains an invalid aci/uuid, needs to be a valid UUID", e);
|
throw new IOException("Config file contains an invalid aci/uuid, needs to be a valid UUID", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rootNode.hasNonNull("pni")) {
|
if (rootNode.hasNonNull("pni")) {
|
||||||
try {
|
try {
|
||||||
pni = PNI.parseOrThrow(rootNode.get("pni").asText());
|
pniAccountData.setServiceId(PNI.parseOrThrow(rootNode.get("pni").asText()));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IOException("Config file contains an invalid pni, needs to be a valid UUID", e);
|
throw new IOException("Config file contains an invalid pni, needs to be a valid UUID", e);
|
||||||
}
|
}
|
||||||
|
@ -980,8 +978,8 @@ public class SignalAccount implements Closeable {
|
||||||
.put("username", number)
|
.put("username", number)
|
||||||
.put("serviceEnvironment", serviceEnvironment == null ? null : serviceEnvironment.name())
|
.put("serviceEnvironment", serviceEnvironment == null ? null : serviceEnvironment.name())
|
||||||
.put("usernameIdentifier", username)
|
.put("usernameIdentifier", username)
|
||||||
.put("uuid", aci == null ? null : aci.toString())
|
.put("uuid", getAci() == null ? null : getAci().toString())
|
||||||
.put("pni", pni == null ? null : pni.toStringWithoutPrefix())
|
.put("pni", getPni() == null ? null : getPni().toStringWithoutPrefix())
|
||||||
.put("deviceName", encryptedDeviceName)
|
.put("deviceName", encryptedDeviceName)
|
||||||
.put("deviceId", deviceId)
|
.put("deviceId", deviceId)
|
||||||
.put("isMultiDevice", isMultiDevice)
|
.put("isMultiDevice", isMultiDevice)
|
||||||
|
@ -1195,17 +1193,17 @@ public class SignalAccount implements Closeable {
|
||||||
return previousStorageVersion;
|
return previousStorageVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountData getAccountData(ServiceIdType serviceIdType) {
|
public AccountData<? extends ServiceId> getAccountData(ServiceIdType serviceIdType) {
|
||||||
return switch (serviceIdType) {
|
return switch (serviceIdType) {
|
||||||
case ACI -> aciAccountData;
|
case ACI -> aciAccountData;
|
||||||
case PNI -> pniAccountData;
|
case PNI -> pniAccountData;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountData getAccountData(ServiceId accountIdentifier) {
|
public AccountData<? extends ServiceId> getAccountData(ServiceId accountIdentifier) {
|
||||||
if (accountIdentifier.equals(aci)) {
|
if (accountIdentifier.equals(aciAccountData.getServiceId())) {
|
||||||
return aciAccountData;
|
return aciAccountData;
|
||||||
} else if (accountIdentifier.equals(pni)) {
|
} else if (accountIdentifier.equals(pniAccountData.getServiceId())) {
|
||||||
return pniAccountData;
|
return pniAccountData;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("No matching account data found for " + accountIdentifier);
|
throw new IllegalArgumentException("No matching account data found for " + accountIdentifier);
|
||||||
|
@ -1216,13 +1214,7 @@ public class SignalAccount implements Closeable {
|
||||||
return new SignalServiceDataStore() {
|
return new SignalServiceDataStore() {
|
||||||
@Override
|
@Override
|
||||||
public SignalServiceAccountDataStore get(final ServiceId accountIdentifier) {
|
public SignalServiceAccountDataStore get(final ServiceId accountIdentifier) {
|
||||||
if (accountIdentifier.equals(aci)) {
|
return getAccountData(accountIdentifier).getSignalServiceAccountDataStore();
|
||||||
return aci();
|
|
||||||
} else if (accountIdentifier.equals(pni)) {
|
|
||||||
return pni();
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("No matching store found for " + accountIdentifier);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1327,12 +1319,12 @@ public class SignalAccount implements Closeable {
|
||||||
return new CredentialsProvider() {
|
return new CredentialsProvider() {
|
||||||
@Override
|
@Override
|
||||||
public ACI getAci() {
|
public ACI getAci() {
|
||||||
return aci;
|
return aciAccountData.getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PNI getPni() {
|
public PNI getPni() {
|
||||||
return pni;
|
return pniAccountData.getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1400,30 +1392,31 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceId getAccountId(ServiceIdType serviceIdType) {
|
public ServiceId getAccountId(ServiceIdType serviceIdType) {
|
||||||
return serviceIdType.equals(ServiceIdType.ACI) ? aci : pni;
|
return getAccountData(serviceIdType).getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ACI getAci() {
|
public ACI getAci() {
|
||||||
return aci;
|
return aciAccountData.getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAci(final ACI aci) {
|
public void setAci(final ACI aci) {
|
||||||
this.aci = aci;
|
this.aciAccountData.setServiceId(aci);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PNI getPni() {
|
public PNI getPni() {
|
||||||
return pni;
|
return pniAccountData.getServiceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPni(final PNI updatedPni) {
|
public void setPni(final PNI updatedPni) {
|
||||||
if (this.pni != null && !this.pni.equals(updatedPni)) {
|
final var oldPni = pniAccountData.getServiceId();
|
||||||
|
if (oldPni != null && !oldPni.equals(updatedPni)) {
|
||||||
// Clear data for old PNI
|
// Clear data for old PNI
|
||||||
identityKeyStore.deleteIdentity(this.pni);
|
identityKeyStore.deleteIdentity(oldPni);
|
||||||
clearAllPreKeys(ServiceIdType.PNI);
|
clearAllPreKeys(ServiceIdType.PNI);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pni = updatedPni;
|
this.pniAccountData.setServiceId(updatedPni);
|
||||||
trustSelfIdentity(ServiceIdType.PNI);
|
trustSelfIdentity(ServiceIdType.PNI);
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
@ -1448,11 +1441,11 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignalServiceAddress getSelfAddress() {
|
public SignalServiceAddress getSelfAddress() {
|
||||||
return new SignalServiceAddress(aci, number);
|
return new SignalServiceAddress(getAci(), number);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipientAddress getSelfRecipientAddress() {
|
public RecipientAddress getSelfRecipientAddress() {
|
||||||
return new RecipientAddress(aci, pni, number, username);
|
return new RecipientAddress(getAci(), getPni(), number, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipientId getSelfRecipientId() {
|
public RecipientId getSelfRecipientId() {
|
||||||
|
@ -1764,9 +1757,10 @@ public class SignalAccount implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AccountData {
|
public class AccountData<SERVICE_ID extends ServiceId> {
|
||||||
|
|
||||||
private final ServiceIdType serviceIdType;
|
private final ServiceIdType serviceIdType;
|
||||||
|
private SERVICE_ID serviceId;
|
||||||
private IdentityKeyPair identityKeyPair;
|
private IdentityKeyPair identityKeyPair;
|
||||||
private int localRegistrationId;
|
private int localRegistrationId;
|
||||||
private final PreKeyMetadata preKeyMetadata = new PreKeyMetadata();
|
private final PreKeyMetadata preKeyMetadata = new PreKeyMetadata();
|
||||||
|
@ -1778,12 +1772,16 @@ public class SignalAccount implements Closeable {
|
||||||
private SessionStore sessionStore;
|
private SessionStore sessionStore;
|
||||||
private SignalIdentityKeyStore identityKeyStore;
|
private SignalIdentityKeyStore identityKeyStore;
|
||||||
|
|
||||||
public AccountData(final ServiceIdType serviceIdType) {
|
private AccountData(final ServiceIdType serviceIdType) {
|
||||||
this.serviceIdType = serviceIdType;
|
this.serviceIdType = serviceIdType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceId getServiceId() {
|
public SERVICE_ID getServiceId() {
|
||||||
return getAccountId(serviceIdType);
|
return serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setServiceId(final SERVICE_ID serviceId) {
|
||||||
|
this.serviceId = serviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentityKeyPair getIdentityKeyPair() {
|
public IdentityKeyPair getIdentityKeyPair() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue