mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Upload attachment before sending to fix sending attachments to multiple recipients
Fixes #259
This commit is contained in:
parent
4bafc7212a
commit
eca1737d28
2 changed files with 18 additions and 5 deletions
|
@ -647,7 +647,20 @@ public class Manager implements Signal {
|
|||
throws IOException, EncapsulatedExceptions, AttachmentInvalidException {
|
||||
final SignalServiceDataMessage.Builder messageBuilder = SignalServiceDataMessage.newBuilder().withBody(messageText);
|
||||
if (attachments != null) {
|
||||
messageBuilder.withAttachments(Utils.getSignalServiceAttachments(attachments));
|
||||
List<SignalServiceAttachment> attachmentStreams = Utils.getSignalServiceAttachments(attachments);
|
||||
|
||||
// Upload attachments here, so we only upload once even for multiple recipients
|
||||
SignalServiceMessageSender messageSender = getMessageSender();
|
||||
List<SignalServiceAttachment> attachmentPointers = new ArrayList<>(attachmentStreams.size());
|
||||
for (SignalServiceAttachment attachment : attachmentStreams) {
|
||||
if (attachment.isStream()) {
|
||||
attachmentPointers.add(messageSender.uploadAttachment(attachment.asStream()));
|
||||
} else if (attachment.isPointer()) {
|
||||
attachmentPointers.add(attachment.asPointer());
|
||||
}
|
||||
}
|
||||
|
||||
messageBuilder.withAttachments(attachmentPointers);
|
||||
}
|
||||
messageBuilder.withProfileKey(account.getProfileKey());
|
||||
sendMessageLegacy(messageBuilder, recipients);
|
||||
|
|
|
@ -47,18 +47,18 @@ import static org.whispersystems.signalservice.internal.util.Util.isEmpty;
|
|||
class Utils {
|
||||
|
||||
static List<SignalServiceAttachment> getSignalServiceAttachments(List<String> attachments) throws AttachmentInvalidException {
|
||||
List<SignalServiceAttachment> SignalServiceAttachments = null;
|
||||
List<SignalServiceAttachment> signalServiceAttachments = null;
|
||||
if (attachments != null) {
|
||||
SignalServiceAttachments = new ArrayList<>(attachments.size());
|
||||
signalServiceAttachments = new ArrayList<>(attachments.size());
|
||||
for (String attachment : attachments) {
|
||||
try {
|
||||
SignalServiceAttachments.add(createAttachment(new File(attachment)));
|
||||
signalServiceAttachments.add(createAttachment(new File(attachment)));
|
||||
} catch (IOException e) {
|
||||
throw new AttachmentInvalidException(attachment, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return SignalServiceAttachments;
|
||||
return signalServiceAttachments;
|
||||
}
|
||||
|
||||
private static String getFileMimeType(File file) throws IOException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue