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

@ -642,7 +642,7 @@ public interface Signal extends DBusInterface {
@DBusProperty(name = "Fingerprint", type = Byte[].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 = "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)
interface Identity extends DBusInterface, Properties {

View file

@ -34,7 +34,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
theirId.recipient().getLegacyIdentifier(),
theirId.trustLevel(),
DateUtils.formatTimestamp(theirId.dateAddedTimestamp()),
Hex.toString(theirId.getFingerprint()),
Hex.toString(theirId.fingerprint()),
Util.formatSafetyNumber(theirId.safetyNumber()));
}
@ -70,7 +70,7 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
var scannableSafetyNumber = id.scannableSafetyNumber();
return new JsonIdentity(address.number().orElse(null),
address.uuid().map(UUID::toString).orElse(null),
Hex.toString(id.getFingerprint()),
Hex.toString(id.fingerprint()),
safetyNumber,
scannableSafetyNumber == 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.StickerPackInvalidException;
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.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
@ -759,12 +760,26 @@ public class DbusManagerImpl implements Manager {
@Override
public List<Identity> getIdentities() {
throw new UnsupportedOperationException();
final var identities = signal.listIdentities();
return identities.stream().map(Signal.StructIdentity::getObjectPath).map(this::getIdentity).toList();
}
@Override
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

View file

@ -1105,7 +1105,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
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::fingerprint),
new DbusProperty<>("SafetyNumber", identity::safetyNumber),
new DbusProperty<>("ScannableSafetyNumber", identity::scannableSafetyNumber),
new DbusProperty<>("TrustLevel", identity::trustLevel),