From 3d5c440aa24227f7a9a387dd675c6f5844d9c293 Mon Sep 17 00:00:00 2001 From: AsamK Date: Sun, 11 Jun 2023 16:39:54 +0200 Subject: [PATCH] Improve uuid/number handling --- man/signal-cli-dbus.5.adoc | 10 ++++++---- src/main/java/org/asamk/Signal.java | 10 +++++----- .../org/asamk/signal/dbus/DbusSignalImpl.java | 16 ++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/man/signal-cli-dbus.5.adoc b/man/signal-cli-dbus.5.adoc index 0f11ef9d..1f2caa18 100644 --- a/man/signal-cli-dbus.5.adoc +++ b/man/signal-cli-dbus.5.adoc @@ -422,12 +422,12 @@ listIdentities() -> identities:: * identities : Array of structs (objectPath, id, name) ** objectPath : DBusPath representing the identity object path ** 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 getIdentity(Number) -> identityPath:: -* Number : Phone number +* Number : Phone number * identityPath : DBusPath object for the identity Gets the identity Dbus path for a given phone number @@ -575,13 +575,15 @@ To get all properties, use: 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 trustVerified(SafetyNumber) -> <>:: -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 diff --git a/src/main/java/org/asamk/Signal.java b/src/main/java/org/asamk/Signal.java index 0a508548..9bffd6af 100644 --- a/src/main/java/org/asamk/Signal.java +++ b/src/main/java/org/asamk/Signal.java @@ -564,12 +564,12 @@ public interface Signal extends DBusInterface { String uuid; @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.uuid = uuid; - this.name = name; + this.number = number; } public DBusPath getObjectPath() { @@ -580,8 +580,8 @@ public interface Signal extends DBusInterface { return uuid; } - public String getName() { - return name; + public String getNumber() { + return number; } } diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index f6ea4eef..fef6821a 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -1044,8 +1044,8 @@ public class DbusSignalImpl implements Signal { final var object = new DbusSignalIdentityImpl(i); exportObject(object); this.identities.add(new StructIdentity(new DBusPath(object.getObjectPath()), - emptyIfNull(i.recipient().getIdentifier()), - i.recipient().getLegacyIdentifier())); + i.recipient().uuid().map(UUID::toString).orElse(""), + i.recipient().number().orElse(""))); }); } @@ -1063,11 +1063,12 @@ public class DbusSignalImpl implements Signal { @Override public DBusPath getIdentity(String number) throws Error.Failure { - - final var found = identities.stream().filter(identity -> identity.getName().equals(number)).findFirst(); + final var found = identities.stream() + .filter(identity -> identity.getNumber().equals(number) || identity.getUuid().equals(number)) + .findFirst(); if (found.isEmpty()) { - throw new Error.Failure("Identity for " + number + " unkown"); + throw new Error.Failure("Identity for " + number + " unknown"); } return found.get().getObjectPath(); } @@ -1088,7 +1089,7 @@ public class DbusSignalImpl implements Signal { List.of(new DbusProperty<>("Number", () -> identity.recipient().number().orElse("")), new DbusProperty<>("Uuid", () -> identity.recipient().uuid().map(UUID::toString).orElse("")), - new DbusProperty<>("Fingerprint", () -> identity.getFingerprint()), + new DbusProperty<>("Fingerprint", identity::getFingerprint), new DbusProperty<>("SafetyNumber", identity::safetyNumber), new DbusProperty<>("ScannableSafetyNumber", identity::scannableSafetyNumber), new DbusProperty<>("TrustLevel", identity::trustLevel), @@ -1181,8 +1182,7 @@ public class DbusSignalImpl implements Signal { public class DbusSignalConfigurationImpl extends DbusProperties implements Signal.Configuration { - public DbusSignalConfigurationImpl( - ) { + public DbusSignalConfigurationImpl() { super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Configuration", List.of(new DbusProperty<>("ReadReceipts", this::getReadReceipts, this::setReadReceipts), new DbusProperty<>("UnidentifiedDeliveryIndicators", -- 2.50.1