Add method to list linked devices
This commit is contained in:
		
							parent
							
								
									800b92c4ba
								
							
						
					
					
						commit
						17ff7531d4
					
				@ -29,6 +29,7 @@ import org.freedesktop.dbus.exceptions.DBusExecutionException;
 | 
				
			|||||||
import org.whispersystems.libsignal.InvalidKeyException;
 | 
					import org.whispersystems.libsignal.InvalidKeyException;
 | 
				
			||||||
import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
 | 
					import org.whispersystems.signalservice.api.crypto.UntrustedIdentityException;
 | 
				
			||||||
import org.whispersystems.signalservice.api.messages.*;
 | 
					import org.whispersystems.signalservice.api.messages.*;
 | 
				
			||||||
 | 
					import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo;
 | 
				
			||||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
 | 
					import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
 | 
				
			||||||
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
 | 
					import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
 | 
				
			||||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
 | 
					import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
 | 
				
			||||||
@ -201,6 +202,28 @@ public class Main {
 | 
				
			|||||||
                        System.exit(2);
 | 
					                        System.exit(2);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
 | 
					                case "listDevices":
 | 
				
			||||||
 | 
					                    if (dBusConn != null) {
 | 
				
			||||||
 | 
					                        System.err.println("listDevices is not yet implemented via dbus");
 | 
				
			||||||
 | 
					                        System.exit(1);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    if (!m.isRegistered()) {
 | 
				
			||||||
 | 
					                        System.err.println("User is not registered.");
 | 
				
			||||||
 | 
					                        System.exit(1);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        List<DeviceInfo> devices = m.getLinkedDevices();
 | 
				
			||||||
 | 
					                        for (DeviceInfo d : devices) {
 | 
				
			||||||
 | 
					                            System.out.println("Device " + d.getId() + (d.getId() == m.getDeviceId() ? " (this device)" : "") + ":");
 | 
				
			||||||
 | 
					                            System.out.println(" Name: " + d.getName());
 | 
				
			||||||
 | 
					                            System.out.println(" Created: " + d.getCreated());
 | 
				
			||||||
 | 
					                            System.out.println(" Last seen: " + d.getLastSeen());
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    } catch (IOException e) {
 | 
				
			||||||
 | 
					                        e.printStackTrace();
 | 
				
			||||||
 | 
					                        System.exit(3);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
                case "send":
 | 
					                case "send":
 | 
				
			||||||
                    if (dBusConn == null && !m.isRegistered()) {
 | 
					                    if (dBusConn == null && !m.isRegistered()) {
 | 
				
			||||||
                        System.err.println("User is not registered.");
 | 
					                        System.err.println("User is not registered.");
 | 
				
			||||||
@ -491,6 +514,8 @@ public class Main {
 | 
				
			|||||||
                .required(true)
 | 
					                .required(true)
 | 
				
			||||||
                .help("Specify the uri contained in the QR code shown by the new device.");
 | 
					                .help("Specify the uri contained in the QR code shown by the new device.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Subparser parserDevices = subparsers.addParser("listDevices");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Subparser parserRegister = subparsers.addParser("register");
 | 
					        Subparser parserRegister = subparsers.addParser("register");
 | 
				
			||||||
        parserRegister.addArgument("-v", "--voice")
 | 
					        parserRegister.addArgument("-v", "--voice")
 | 
				
			||||||
                .help("The verification should be done over voice, not sms.")
 | 
					                .help("The verification should be done over voice, not sms.")
 | 
				
			||||||
 | 
				
			|||||||
@ -79,7 +79,7 @@ class Manager implements Signal {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private final ObjectMapper jsonProcessot = new ObjectMapper();
 | 
					    private final ObjectMapper jsonProcessot = new ObjectMapper();
 | 
				
			||||||
    private String username;
 | 
					    private String username;
 | 
				
			||||||
    int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
 | 
					    private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
 | 
				
			||||||
    private String password;
 | 
					    private String password;
 | 
				
			||||||
    private String signalingKey;
 | 
					    private String signalingKey;
 | 
				
			||||||
    private int preKeyIdOffset;
 | 
					    private int preKeyIdOffset;
 | 
				
			||||||
@ -107,6 +107,10 @@ class Manager implements Signal {
 | 
				
			|||||||
        return username;
 | 
					        return username;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int getDeviceId() {
 | 
				
			||||||
 | 
					        return deviceId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getFileName() {
 | 
					    public String getFileName() {
 | 
				
			||||||
        new File(dataPath).mkdirs();
 | 
					        new File(dataPath).mkdirs();
 | 
				
			||||||
        return dataPath + "/" + username;
 | 
					        return dataPath + "/" + username;
 | 
				
			||||||
@ -256,6 +260,9 @@ class Manager implements Signal {
 | 
				
			|||||||
        save();
 | 
					        save();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<DeviceInfo> getLinkedDevices() throws IOException {
 | 
				
			||||||
 | 
					        return accountManager.getDevices();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static Map<String, String> getQueryMap(String query) {
 | 
					    public static Map<String, String> getQueryMap(String query) {
 | 
				
			||||||
        String[] params = query.split("&");
 | 
					        String[] params = query.split("&");
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user