Improve uuid/number handling

This commit is contained in:
AsamK 2023-06-11 16:39:54 +02:00
parent 4f8da7819e
commit 3d5c440aa2
3 changed files with 19 additions and 17 deletions

View file

@ -422,12 +422,12 @@ listIdentities() -> identities<a(oss)>::
* identities : Array of structs (objectPath, id, name) * identities : Array of structs (objectPath, id, name)
** objectPath : DBusPath representing the identity object path ** objectPath : DBusPath representing the identity object path
** uuid : Internal uuid of the identity ** uuid : Internal uuid of the identity
** number : Phone number of the identity (or uuid if not known) ** number : Phone number of the identity
Lists all know identities Lists all know identities
getIdentity(Number<s>) -> identityPath<o>:: getIdentity(Number<s>) -> identityPath<o>::
* Number : Phone number * Number : Phone number
* identityPath : DBusPath object for the identity * identityPath : DBusPath object for the identity
Gets the identity Dbus path for a given phone number Gets the identity Dbus path for a given phone number
@ -575,13 +575,15 @@ To get all properties, use:
trust() -> <>:: trust() -> <>::
Establish trust with the given identity. TrustLevel will become TRUSTED_UNVERFIED Establish trust with the given identity.
TrustLevel will become TRUSTED_UNVERFIED
Exceptions: Failure Exceptions: Failure
trustVerified(SafetyNumber<s>) -> <>:: trustVerified(SafetyNumber<s>) -> <>::
Establish trust with the given identity using their safety number. TrustLevel will become TRUSTED_VERIFIED Establish trust with the given identity using their safety number.
TrustLevel will become TRUSTED_VERIFIED
Exceptions: Failure Exceptions: Failure

View file

@ -564,12 +564,12 @@ public interface Signal extends DBusInterface {
String uuid; String uuid;
@Position(2) @Position(2)
String name; String number;
public StructIdentity(final DBusPath objectPath, final String uuid, final String name) { public StructIdentity(final DBusPath objectPath, final String uuid, final String number) {
this.objectPath = objectPath; this.objectPath = objectPath;
this.uuid = uuid; this.uuid = uuid;
this.name = name; this.number = number;
} }
public DBusPath getObjectPath() { public DBusPath getObjectPath() {
@ -580,8 +580,8 @@ public interface Signal extends DBusInterface {
return uuid; return uuid;
} }
public String getName() { public String getNumber() {
return name; return number;
} }
} }

View file

@ -1044,8 +1044,8 @@ public class DbusSignalImpl implements Signal {
final var object = new DbusSignalIdentityImpl(i); final var object = new DbusSignalIdentityImpl(i);
exportObject(object); exportObject(object);
this.identities.add(new StructIdentity(new DBusPath(object.getObjectPath()), this.identities.add(new StructIdentity(new DBusPath(object.getObjectPath()),
emptyIfNull(i.recipient().getIdentifier()), i.recipient().uuid().map(UUID::toString).orElse(""),
i.recipient().getLegacyIdentifier())); i.recipient().number().orElse("")));
}); });
} }
@ -1063,11 +1063,12 @@ public class DbusSignalImpl implements Signal {
@Override @Override
public DBusPath getIdentity(String number) throws Error.Failure { public DBusPath getIdentity(String number) throws Error.Failure {
final var found = identities.stream()
final var found = identities.stream().filter(identity -> identity.getName().equals(number)).findFirst(); .filter(identity -> identity.getNumber().equals(number) || identity.getUuid().equals(number))
.findFirst();
if (found.isEmpty()) { if (found.isEmpty()) {
throw new Error.Failure("Identity for " + number + " unkown"); throw new Error.Failure("Identity for " + number + " unknown");
} }
return found.get().getObjectPath(); return found.get().getObjectPath();
} }
@ -1088,7 +1089,7 @@ public class DbusSignalImpl implements Signal {
List.of(new DbusProperty<>("Number", () -> identity.recipient().number().orElse("")), List.of(new DbusProperty<>("Number", () -> identity.recipient().number().orElse("")),
new DbusProperty<>("Uuid", new DbusProperty<>("Uuid",
() -> identity.recipient().uuid().map(UUID::toString).orElse("")), () -> identity.recipient().uuid().map(UUID::toString).orElse("")),
new DbusProperty<>("Fingerprint", () -> identity.getFingerprint()), new DbusProperty<>("Fingerprint", identity::getFingerprint),
new DbusProperty<>("SafetyNumber", identity::safetyNumber), new DbusProperty<>("SafetyNumber", identity::safetyNumber),
new DbusProperty<>("ScannableSafetyNumber", identity::scannableSafetyNumber), new DbusProperty<>("ScannableSafetyNumber", identity::scannableSafetyNumber),
new DbusProperty<>("TrustLevel", identity::trustLevel), new DbusProperty<>("TrustLevel", identity::trustLevel),
@ -1181,8 +1182,7 @@ public class DbusSignalImpl implements Signal {
public class DbusSignalConfigurationImpl extends DbusProperties implements Signal.Configuration { public class DbusSignalConfigurationImpl extends DbusProperties implements Signal.Configuration {
public DbusSignalConfigurationImpl( public DbusSignalConfigurationImpl() {
) {
super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration", super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration",
List.of(new DbusProperty<>("ReadReceipts", this::getReadReceipts, this::setReadReceipts), List.of(new DbusProperty<>("ReadReceipts", this::getReadReceipts, this::setReadReceipts),
new DbusProperty<>("UnidentifiedDeliveryIndicators", new DbusProperty<>("UnidentifiedDeliveryIndicators",