]> nmode's Git Repositories - signal-cli/commitdiff
Allow retreving and updating group info and contact names via dbus (#62)
authorFinn <finn@finn.io>
Wed, 22 Feb 2017 20:26:34 +0000 (12:26 -0800)
committerAsamK <asamk@gmx.de>
Wed, 22 Feb 2017 20:26:34 +0000 (21:26 +0100)
* dbus method to get contact info

* Add getGroupName method

* Save after updating contact name

* allow group updates over dbus

* Allow retreiving group member list as well

* Space after if before conditions if( -> if (

* Return an empty string if the contact is unknown

* Handle null/non-existant groups better

* Remove debug output and allow updating the avatar

* Remove extra variables in update messages

src/main/java/org/asamk/Signal.java
src/main/java/org/asamk/signal/Manager.java

index 02fc22ddf7b352e322176bddc91693db6e3dc023..79bf0172b871d1ef6b35f0ee794024e01921a78d 100644 (file)
@@ -19,6 +19,16 @@ public interface Signal extends DBusInterface {
 
     void sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException;
 
+    String getContactName(String number);
+
+    void setContactName(String number, String name);
+
+    String getGroupName(byte[] groupId);
+
+    List<String> getGroupMembers(byte[] groupId);
+
+    void updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException;
+
     class MessageReceived extends DBusSignal {
         private long timestamp;
         private String sender;
index a50cb481b5521b0c4c291c9ea44a70d06aae53ef..4a5d46805c8901c8df668b2ec516bc449ad9f52a 100644 (file)
@@ -779,6 +779,65 @@ class Manager implements Signal {
         sendMessage(messageBuilder, recipients);
     }
 
+    @Override
+    public String getContactName(String number) {
+        ContactInfo contact = contactStore.getContact(number);
+        if (contact == null) {
+            return "";
+        } else {
+            return contact.name;
+        }
+    }
+
+    @Override
+    public void setContactName(String number, String name) {
+        ContactInfo contact = contactStore.getContact(number);
+        if (contact == null) {
+            contact = new ContactInfo();
+            contact.number = number;
+            System.out.println("Add contact " + number + " named " + name);
+        } else {
+            System.out.println("Updating contact " + number + " name " + contact.name + " -> " + name);
+        }
+        contact.name = name;
+        contactStore.updateContact(contact);
+        save();
+    }
+
+    @Override
+    public String getGroupName(byte[] groupId) {
+        GroupInfo group = getGroup(groupId);
+        if (group == null) {
+            return "";
+        } else {
+            return group.name;
+        }
+    }
+
+    @Override
+    public List<String> getGroupMembers(byte[] groupId) {
+        GroupInfo group = getGroup(groupId);
+        if (group == null) {
+            return new ArrayList<String>();
+        } else {
+            return new ArrayList<String>(group.members);
+        }
+    }
+
+    @Override
+    public void updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
+        if (name.isEmpty()) {
+            name = null;
+        }
+        if (members.size() == 0) {
+            members = null;
+        }
+        if (avatar.isEmpty()) {
+            avatar = null;
+        }
+        sendUpdateGroupMessage(groupId, name, members, avatar);
+    }
+
     private void requestSyncGroups() throws IOException {
         SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build();
         SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));