private final static int PREKEY_MINIMUM_COUNT = 20;
private static final int PREKEY_BATCH_SIZE = 100;
+ private static final int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024;
private final String settingsPath;
private final String dataPath;
if (mime == null) {
mime = "application/octet-stream";
}
- return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, null);
+ // TODO mabybe add a parameter to set the voiceNote and preview option
+ return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, Optional.<byte[]>absent(),null);
}
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
}
@Override
- public void updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
+ public byte[] updateGroup(byte[] groupId, String name, List<String> members, String avatar) throws IOException, EncapsulatedExceptions, GroupNotFoundException, AttachmentInvalidException {
+ if (groupId.length == 0) {
+ groupId = null;
+ }
if (name.isEmpty()) {
name = null;
}
if (avatar.isEmpty()) {
avatar = null;
}
- sendUpdateGroupMessage(groupId, name, members, avatar);
+ return sendUpdateGroupMessage(groupId, name, members, avatar);
}
private void requestSyncGroups() throws IOException {
File tmpFile = null;
try {
tmpFile = Util.createTempFile();
- DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(syncMessage.getContacts().get().asPointer(), tmpFile));
+ final ContactsMessage contactsMessage = syncMessage.getContacts().get();
+ DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(contactsMessage.getContactsStream().asPointer(), tmpFile));
+ if (contactsMessage.isComplete()) {
+ contactStore.clear();
+ }
DeviceContact c;
while ((c = s.read()) != null) {
ContactInfo contact = contactStore.getContact(c.getNumber());
final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(serviceUrls, username, password, deviceId, signalingKey, USER_AGENT);
File tmpFile = Util.createTempFile();
- try (InputStream input = messageReceiver.retrieveAttachment(pointer, tmpFile)) {
+ try (InputStream input = messageReceiver.retrieveAttachment(pointer, tmpFile, MAX_ATTACHMENT_SIZE)) {
try (OutputStream output = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[4096];
int read;
private InputStream retrieveAttachmentAsStream(SignalServiceAttachmentPointer pointer, File tmpFile) throws IOException, InvalidMessageException {
final SignalServiceMessageReceiver messageReceiver = new SignalServiceMessageReceiver(serviceUrls, username, password, deviceId, signalingKey, USER_AGENT);
- return messageReceiver.retrieveAttachment(pointer, tmpFile);
+ return messageReceiver.retrieveAttachment(pointer, tmpFile, MAX_ATTACHMENT_SIZE);
}
private String canonicalizeNumber(String number) throws InvalidNumberException {
.withLength(contactsFile.length())
.build();
- sendSyncMessage(SignalServiceSyncMessage.forContacts(attachmentStream));
+ sendSyncMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, true)));
}
}
} finally {