Implement dbus support for listIdentities

Fixes #195
This commit is contained in:
AsamK 2024-04-19 17:07:18 +02:00
parent e4c5144fbf
commit c1775913b9
8 changed files with 31 additions and 18 deletions

View file

@ -14,6 +14,9 @@
{ {
"interfaces":["org.asamk.Signal$Group"] "interfaces":["org.asamk.Signal$Group"]
}, },
{
"interfaces":["org.asamk.Signal$Identity"]
},
{ {
"interfaces":["org.asamk.SignalControl"] "interfaces":["org.asamk.SignalControl"]
}, },

View file

@ -572,7 +572,7 @@
"name":"org.asamk.Signal", "name":"org.asamk.Signal",
"allDeclaredMethods":true, "allDeclaredMethods":true,
"allDeclaredClasses":true, "allDeclaredClasses":true,
"methods":[{"name":"getContactName","parameterTypes":["java.lang.String"] }, {"name":"getDevice","parameterTypes":["long"] }, {"name":"getGroup","parameterTypes":["byte[]"] }, {"name":"getSelfNumber","parameterTypes":[] }, {"name":"getThisDevice","parameterTypes":[] }, {"name":"listDevices","parameterTypes":[] }, {"name":"sendGroupMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","byte[]"] }, {"name":"sendMessage","parameterTypes":["java.lang.String","java.util.List","java.lang.String"] }, {"name":"sendMessage","parameterTypes":["java.lang.String","java.util.List","java.util.List"] }, {"name":"sendMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","java.util.List"] }, {"name":"subscribeReceive","parameterTypes":[] }, {"name":"unsubscribeReceive","parameterTypes":[] }, {"name":"version","parameterTypes":[] }] "methods":[{"name":"getContactName","parameterTypes":["java.lang.String"] }, {"name":"getDevice","parameterTypes":["long"] }, {"name":"getGroup","parameterTypes":["byte[]"] }, {"name":"getSelfNumber","parameterTypes":[] }, {"name":"getThisDevice","parameterTypes":[] }, {"name":"listDevices","parameterTypes":[] }, {"name":"listIdentities","parameterTypes":[] }, {"name":"sendGroupMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","byte[]"] }, {"name":"sendMessage","parameterTypes":["java.lang.String","java.util.List","java.lang.String"] }, {"name":"sendMessage","parameterTypes":["java.lang.String","java.util.List","java.util.List"] }, {"name":"sendMessageReaction","parameterTypes":["java.lang.String","boolean","java.lang.String","long","java.util.List"] }, {"name":"subscribeReceive","parameterTypes":[] }, {"name":"unsubscribeReceive","parameterTypes":[] }, {"name":"version","parameterTypes":[] }]
}, },
{ {
"name":"org.asamk.Signal$Configuration", "name":"org.asamk.Signal$Configuration",
@ -651,7 +651,9 @@
}, },
{ {
"name":"org.asamk.Signal$StructIdentity", "name":"org.asamk.Signal$StructIdentity",
"allDeclaredFields":true "allDeclaredFields":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"<init>","parameterTypes":["org.freedesktop.dbus.DBusPath","java.lang.String","java.lang.String"] }]
}, },
{ {
"name":"org.asamk.Signal$SyncMessageReceived", "name":"org.asamk.Signal$SyncMessageReceived",

View file

@ -1,17 +1,10 @@
package org.asamk.signal.manager.api; package org.asamk.signal.manager.api;
import org.signal.libsignal.protocol.IdentityKey;
public record Identity( public record Identity(
RecipientAddress recipient, RecipientAddress recipient,
IdentityKey identityKey, byte[] fingerprint,
String safetyNumber, String safetyNumber,
byte[] scannableSafetyNumber, byte[] scannableSafetyNumber,
TrustLevel trustLevel, TrustLevel trustLevel,
long dateAddedTimestamp long dateAddedTimestamp
) { ) {}
public byte[] getFingerprint() {
return identityKey.getPublicKey().serialize();
}
}

View file

@ -1366,7 +1366,7 @@ public class ManagerImpl implements Manager {
final var scannableFingerprint = context.getIdentityHelper() final var scannableFingerprint = context.getIdentityHelper()
.computeSafetyNumberForScanning(identityInfo.getServiceId(), identityInfo.getIdentityKey()); .computeSafetyNumberForScanning(identityInfo.getServiceId(), identityInfo.getIdentityKey());
return new Identity(address.toApiRecipientAddress(), return new Identity(address.toApiRecipientAddress(),
identityInfo.getIdentityKey(), identityInfo.getIdentityKey().getPublicKey().serialize(),
context.getIdentityHelper() context.getIdentityHelper()
.computeSafetyNumber(identityInfo.getServiceId(), identityInfo.getIdentityKey()), .computeSafetyNumber(identityInfo.getServiceId(), identityInfo.getIdentityKey()),
scannableFingerprint == null ? null : scannableFingerprint.getSerialized(), scannableFingerprint == null ? null : scannableFingerprint.getSerialized(),

View file

@ -642,7 +642,7 @@ public interface Signal extends DBusInterface {
@DBusProperty(name = "Fingerprint", type = Byte[].class, access = DBusProperty.Access.READ) @DBusProperty(name = "Fingerprint", type = Byte[].class, access = DBusProperty.Access.READ)
@DBusProperty(name = "SafetyNumber", type = String.class, access = DBusProperty.Access.READ) @DBusProperty(name = "SafetyNumber", type = String.class, access = DBusProperty.Access.READ)
@DBusProperty(name = "TrustLevel", type = String.class, access = DBusProperty.Access.READ) @DBusProperty(name = "TrustLevel", type = String.class, access = DBusProperty.Access.READ)
@DBusProperty(name = "AddedDate", type = Integer.class, access = DBusProperty.Access.READ) @DBusProperty(name = "AddedDate", type = Long.class, access = DBusProperty.Access.READ)
@DBusProperty(name = "ScannableSafetyNumber", type = Byte[].class, access = DBusProperty.Access.READ) @DBusProperty(name = "ScannableSafetyNumber", type = Byte[].class, access = DBusProperty.Access.READ)
interface Identity extends DBusInterface, Properties { interface Identity extends DBusInterface, Properties {

View file

@ -34,7 +34,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
theirId.recipient().getLegacyIdentifier(), theirId.recipient().getLegacyIdentifier(),
theirId.trustLevel(), theirId.trustLevel(),
DateUtils.formatTimestamp(theirId.dateAddedTimestamp()), DateUtils.formatTimestamp(theirId.dateAddedTimestamp()),
Hex.toString(theirId.getFingerprint()), Hex.toString(theirId.fingerprint()),
Util.formatSafetyNumber(theirId.safetyNumber())); Util.formatSafetyNumber(theirId.safetyNumber()));
} }
@ -70,7 +70,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
var scannableSafetyNumber = id.scannableSafetyNumber(); var scannableSafetyNumber = id.scannableSafetyNumber();
return new JsonIdentity(address.number().orElse(null), return new JsonIdentity(address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null), address.uuid().map(UUID::toString).orElse(null),
Hex.toString(id.getFingerprint()), Hex.toString(id.fingerprint()),
safetyNumber, safetyNumber,
scannableSafetyNumber == null scannableSafetyNumber == null
? null ? null

View file

@ -41,6 +41,7 @@ import org.asamk.signal.manager.api.StickerPack;
import org.asamk.signal.manager.api.StickerPackId; import org.asamk.signal.manager.api.StickerPackId;
import org.asamk.signal.manager.api.StickerPackInvalidException; import org.asamk.signal.manager.api.StickerPackInvalidException;
import org.asamk.signal.manager.api.StickerPackUrl; import org.asamk.signal.manager.api.StickerPackUrl;
import org.asamk.signal.manager.api.TrustLevel;
import org.asamk.signal.manager.api.TypingAction; import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException; import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup; import org.asamk.signal.manager.api.UpdateGroup;
@ -759,12 +760,26 @@ public class DbusManagerImpl implements Manager {
@Override @Override
public List<Identity> getIdentities() { public List<Identity> getIdentities() {
throw new UnsupportedOperationException(); final var identities = signal.listIdentities();
return identities.stream().map(Signal.StructIdentity::getObjectPath).map(this::getIdentity).toList();
} }
@Override @Override
public List<Identity> getIdentities(final RecipientIdentifier.Single recipient) { public List<Identity> getIdentities(final RecipientIdentifier.Single recipient) {
throw new UnsupportedOperationException(); final var path = signal.getIdentity(recipient.getIdentifier());
return List.of(getIdentity(path));
}
private Identity getIdentity(final DBusPath identityPath) {
final var group = getRemoteObject(identityPath, Signal.Identity.class).GetAll("org.asamk.Signal.Identity");
final var aci = (String) group.get("Uuid").getValue();
final var number = (String) group.get("Number").getValue();
return new Identity(new RecipientAddress(aci, null, number, null),
(byte[]) group.get("Fingerprint").getValue(),
(String) group.get("SafetyNumber").getValue(),
(byte[]) group.get("ScannableSafetyNumber").getValue(),
TrustLevel.valueOf((String) group.get("TrustLevel").getValue()),
(Long) group.get("AddedDate").getValue());
} }
@Override @Override

View file

@ -1105,7 +1105,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
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::fingerprint),
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),