package org.asamk.signal.dbus;
import org.asamk.Signal;
+import org.asamk.signal.DbusConfig;
import org.asamk.signal.manager.AttachmentInvalidException;
import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.NotMasterDeviceException;
import org.asamk.signal.manager.storage.recipients.Contact;
import org.asamk.signal.manager.storage.recipients.Profile;
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
+import org.freedesktop.dbus.DBusPath;
+import org.freedesktop.dbus.connections.impl.DBusConnection;
+import org.freedesktop.dbus.exceptions.DBusException;
+import org.freedesktop.dbus.interfaces.DBusInterface;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.util.Pair;
public class DbusManagerImpl implements Manager {
private final Signal signal;
+ private final DBusConnection connection;
- public DbusManagerImpl(final Signal signal) {
+ public DbusManagerImpl(final Signal signal, DBusConnection connection) {
this.signal = signal;
+ this.connection = connection;
}
@Override
@Override
public void updateAccountAttributes(final String deviceName) throws IOException {
if (deviceName != null) {
- signal.updateDeviceName(deviceName);
+ final var devicePath = signal.getThisDevice();
+ getRemoteObject(devicePath, Signal.Device.class).Set("org.asamk.Signal.Device", "Name", deviceName);
}
}
final Boolean typingIndicators,
final Boolean linkPreviews
) throws IOException {
- throw new UnsupportedOperationException();
+ signal.setConfiguration(
+ readReceipts,
+ unidentifiedDeliveryIndicators,
+ typingIndicators,
+ linkPreviews
+ );
+ }
+
+ @Override
+ public List<Boolean> getConfiguration() {
+ return signal.getConfiguration();
}
@Override
@Override
public List<Device> getLinkedDevices() throws IOException {
- return signal.listDevices()
- .stream()
- .map(name -> new Device(-1, name, 0, 0, false))
- .collect(Collectors.toList());
+ final var thisDevice = signal.getThisDevice();
+ return signal.listDevices().stream().map(d -> {
+ final var device = getRemoteObject(d.getObjectPath(),
+ Signal.Device.class).GetAll("org.asamk.Signal.Device");
+ return new Device((long) device.get("Id").getValue(),
+ (String) device.get("Name").getValue(),
+ (long) device.get("Created").getValue(),
+ (long) device.get("LastSeen").getValue(),
+ thisDevice.equals(d.getObjectPath()));
+ }).collect(Collectors.toList());
}
@Override
- public void removeLinkedDevices(final int deviceId) throws IOException {
- signal.removeDevice(deviceId);
+ public void removeLinkedDevices(final long deviceId) throws IOException {
+ final var devicePath = signal.getDevice(deviceId);
+ getRemoteObject(devicePath, Signal.Device.class).removeDevice();
}
@Override
private String emptyIfNull(final String string) {
return string == null ? "" : string;
}
+
+ private <T extends DBusInterface> T getRemoteObject(final DBusPath devicePath, final Class<T> type) {
+ try {
+ return connection.getRemoteObject(DbusConfig.getBusname(), devicePath.getPath(), type);
+ } catch (DBusException e) {
+ throw new AssertionError(e);
+ }
+ }
}