Update dependencies, add attachment filename support

Fixes #76
This commit is contained in:
AsamK 2017-04-01 12:46:33 +02:00
parent 474372da6b
commit 3c3d3e92dd
3 changed files with 6 additions and 4 deletions

View file

@ -1038,6 +1038,7 @@ public class Main {
if (attachment.isPointer()) {
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : ""));
System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"));
System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : ""));
File file = m.getAttachmentFile(pointer.getId());
if (file.exists()) {

View file

@ -96,6 +96,7 @@ class Manager implements Signal {
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;
@ -557,7 +558,7 @@ class Manager implements Signal {
if (mime == null) {
mime = "application/octet-stream";
}
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, null);
return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), null);
}
private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
@ -1407,7 +1408,7 @@ class Manager implements Signal {
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;
@ -1431,7 +1432,7 @@ class Manager implements Signal {
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 {