track attachment data (#671 and #316)

create new DbusAttachment type
allow URLs for --attachment option
update manpage
update wiki with signalmail
implement setExpirationTimer() for DBus
implement isRegistered() for DBus
add sendNoteToSelfMessageWithDBusAttachments
add sendGroupMessageWithDBusAttachments
add sendMessageWithDBusAttachments
bump version
This commit is contained in:
John Freed 2021-07-31 18:31:28 +02:00
parent 8f781c019f
commit 8aed357994
18 changed files with 526 additions and 49 deletions

View file

@ -1274,7 +1274,7 @@ public class Manager implements Closeable {
) throws IOException, AttachmentInvalidException, InvalidNumberException {
final var messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
if (attachments != null) {
var attachmentStreams = AttachmentUtils.getSignalServiceAttachments(attachments);
List<SignalServiceAttachment> attachmentStreams = AttachmentUtils.getSignalServiceAttachments(attachments);
// Upload attachments here, so we only upload once even for multiple recipients
var messageSender = createMessageSender();

View file

@ -11,6 +11,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.net.URL;
public class AttachmentUtils {
@ -21,8 +22,13 @@ public class AttachmentUtils {
for (var attachment : attachments) {
try {
signalServiceAttachments.add(createAttachment(new File(attachment)));
} catch (IOException e) {
throw new AttachmentInvalidException(attachment, e);
} catch (IOException f) {
// no such file, send it as URL
try {
signalServiceAttachments.add(createAttachment(new URL(attachment)));
} catch (IOException e) {
throw new AttachmentInvalidException(attachment, e);
}
}
}
}
@ -34,25 +40,39 @@ public class AttachmentUtils {
return createAttachment(streamDetails, Optional.of(attachmentFile.getName()));
}
public static SignalServiceAttachmentStream createAttachment(URL aURL) throws IOException {
final var streamDetails = Utils.createStreamDetailsFromURL(aURL);
String path = aURL.getPath();
String name = path.substring(path.lastIndexOf('/') + 1);
return createAttachment(streamDetails, Optional.of(name));
}
public static SignalServiceAttachmentStream createAttachment(
StreamDetails streamDetails, Optional<String> name
) {
// TODO mabybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
// TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height, caption, blurHash options
final var uploadTimestamp = System.currentTimeMillis();
boolean voicenote = false;
boolean borderless = false;
Optional<byte[]> preview = Optional.absent();
int width = 0;
int height = 0;
Optional<String> caption = Optional.absent();
Optional<String> blurHash = Optional.absent();
final Optional<ResumableUploadSpec> resumableUploadSpec = Optional.absent();
//ProgressListener listener = null; //Android OS
//CancellationSignal cancellationSignal = null; //Android OS; Signal developers misspelled class name
return new SignalServiceAttachmentStream(streamDetails.getStream(),
streamDetails.getContentType(),
streamDetails.getLength(),
name,
false,
false,
voicenote,
borderless,
false,
preview,
0,
0,
width,
height,
uploadTimestamp,
caption,
blurHash,

View file

@ -11,6 +11,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
@ -36,6 +37,13 @@ public class Utils {
return new StreamDetails(stream, mime, size);
}
public static StreamDetails createStreamDetailsFromURL(URL aURL) throws IOException {
InputStream stream = aURL.openStream();
final var mime = aURL.openConnection().getContentType();
final var size = aURL.openConnection().getContentLengthLong();
return new StreamDetails(stream, mime, size);
}
public static String computeSafetyNumber(
boolean isUuidCapable,
SignalServiceAddress ownAddress,