Allow retreving and updating group info and contact names via dbus (#62)

* 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
This commit is contained in:
Finn 2017-02-22 12:26:34 -08:00 committed by AsamK
parent 8cd782ef94
commit 6f2e8716c7
2 changed files with 69 additions and 0 deletions

View file

@ -19,6 +19,16 @@ public interface Signal extends DBusInterface {
void sendGroupMessage(String message, List<String> attachments, byte[] groupId) throws EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException, IOException; 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 { class MessageReceived extends DBusSignal {
private long timestamp; private long timestamp;
private String sender; private String sender;

View file

@ -779,6 +779,65 @@ class Manager implements Signal {
sendMessage(messageBuilder, recipients); 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 { private void requestSyncGroups() throws IOException {
SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build(); SignalServiceProtos.SyncMessage.Request r = SignalServiceProtos.SyncMessage.Request.newBuilder().setType(SignalServiceProtos.SyncMessage.Request.Type.GROUPS).build();
SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r)); SignalServiceSyncMessage message = SignalServiceSyncMessage.forRequest(new RequestMessage(r));