mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
implement Dbus updateAccount and listDevices (#730)
* implement Dbus updateAccount and listDevices implement updateAccount(deviceName<s>) to change device name implement listDevices update documentation * implement Dbus addDevice and removeDevice update documentation as well * Dbus add/remove/list/update devices modifications responding to requests by AsamK * Dbus incorporating InvalidUri error Co-authored-by: AsamK <asamk@gmx.de>
This commit is contained in:
parent
d47574351e
commit
e78463ea0a
3 changed files with 144 additions and 0 deletions
|
@ -7,6 +7,7 @@ import org.asamk.signal.manager.Manager;
|
|||
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||
import org.asamk.signal.manager.StickerPackInvalidException;
|
||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||
import org.asamk.signal.manager.api.Device;
|
||||
import org.asamk.signal.manager.api.Message;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
|
@ -20,6 +21,7 @@ import org.asamk.signal.manager.storage.identities.IdentityInfo;
|
|||
import org.asamk.signal.util.ErrorUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
|
||||
|
@ -30,6 +32,8 @@ import org.whispersystems.signalservice.internal.contacts.crypto.Unauthenticated
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -62,6 +66,51 @@ public class DbusSignalImpl implements Signal {
|
|||
return objectPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(String uri) {
|
||||
try {
|
||||
m.addDeviceLink(new URI(uri));
|
||||
} catch (IOException | InvalidKeyException e) {
|
||||
throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new Error.InvalidUri(e.getClass().getSimpleName() + " Device link uri has invalid format: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDevice(int deviceId) {
|
||||
try {
|
||||
m.removeLinkedDevices(deviceId);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getClass().getSimpleName() + ": Error while removing device: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listDevices() {
|
||||
List<Device> devices;
|
||||
List<String> results = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
devices = m.getLinkedDevices();
|
||||
} catch (IOException | Error.Failure e) {
|
||||
throw new Error.Failure("Failed to get linked devices: " + e.getMessage());
|
||||
}
|
||||
|
||||
return devices.stream()
|
||||
.map(d -> d.getName() == null ? "" : d.getName())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceName(String deviceName) {
|
||||
try {
|
||||
m.updateAccountAttributes(deviceName);
|
||||
} catch (IOException | Signal.Error.Failure e) {
|
||||
throw new Error.Failure("UpdateAccount error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
|
||||
var recipients = new ArrayList<String>(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue