+
+ private void sendGroups() throws IOException, UntrustedIdentityException {
+ File groupsFile = File.createTempFile("multidevice-group-update", ".tmp");
+
+ try {
+ DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(new FileOutputStream(groupsFile));
+ try {
+ for (GroupInfo record : groupStore.getGroups()) {
+ out.write(new DeviceGroup(record.groupId, Optional.fromNullable(record.name),
+ new ArrayList<>(record.members), createGroupAvatarAttachment(record.groupId),
+ record.active));
+ }
+ } finally {
+ out.close();
+ }
+
+ if (groupsFile.exists() && groupsFile.length() > 0) {
+ FileInputStream contactsFileStream = new FileInputStream(groupsFile);
+ SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
+ .withStream(contactsFileStream)
+ .withContentType("application/octet-stream")
+ .withLength(groupsFile.length())
+ .build();
+
+ sendMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
+ }
+ } finally {
+ groupsFile.delete();
+ }
+ }
+
+ private void sendContacts() throws IOException, UntrustedIdentityException {
+ File contactsFile = File.createTempFile("multidevice-contact-update", ".tmp");
+
+ try {
+ DeviceContactsOutputStream out = new DeviceContactsOutputStream(new FileOutputStream(contactsFile));
+ try {
+ for (ContactInfo record : contactStore.getContacts()) {
+ out.write(new DeviceContact(record.number, Optional.fromNullable(record.name),
+ createContactAvatarAttachment(record.number)));
+ }
+ } finally {
+ out.close();
+ }
+
+ if (contactsFile.exists() && contactsFile.length() > 0) {
+ FileInputStream contactsFileStream = new FileInputStream(contactsFile);
+ SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
+ .withStream(contactsFileStream)
+ .withContentType("application/octet-stream")
+ .withLength(contactsFile.length())
+ .build();
+
+ sendMessage(SignalServiceSyncMessage.forContacts(attachmentStream));
+ }
+ } finally {
+ contactsFile.delete();
+ }
+ }
+
+ public ContactInfo getContact(String number) {
+ return contactStore.getContact(number);
+ }
+
+ public GroupInfo getGroup(byte[] groupId) {
+ return groupStore.getGroup(groupId);
+ }