1 package org
.asamk
.signal
.manager
.util
;
3 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
4 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachmentStream
;
5 import org
.whispersystems
.signalservice
.api
.util
.StreamDetails
;
6 import org
.whispersystems
.signalservice
.internal
.push
.http
.ResumableUploadSpec
;
9 import java
.io
.IOException
;
10 import java
.util
.ArrayList
;
11 import java
.util
.List
;
12 import java
.util
.Optional
;
14 public class AttachmentUtils
{
16 public static List
<SignalServiceAttachmentStream
> createAttachmentStreams(List
<String
> attachments
) throws AttachmentInvalidException
{
17 if (attachments
== null) {
20 final var signalServiceAttachments
= new ArrayList
<SignalServiceAttachmentStream
>(attachments
.size());
21 for (var attachment
: attachments
) {
22 signalServiceAttachments
.add(createAttachmentStream(new File(attachment
)));
24 return signalServiceAttachments
;
27 public static SignalServiceAttachmentStream
createAttachmentStream(File attachmentFile
) throws AttachmentInvalidException
{
29 final var streamDetails
= Utils
.createStreamDetailsFromFile(attachmentFile
);
30 return createAttachmentStream(streamDetails
, Optional
.of(attachmentFile
.getName()));
31 } catch (IOException e
) {
32 throw new AttachmentInvalidException(attachmentFile
.toString(), e
);
36 public static SignalServiceAttachmentStream
createAttachmentStream(
37 StreamDetails streamDetails
, Optional
<String
> name
39 // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
40 final var uploadTimestamp
= System
.currentTimeMillis();
41 Optional
<byte[]> preview
= Optional
.empty();
42 Optional
<String
> caption
= Optional
.empty();
43 Optional
<String
> blurHash
= Optional
.empty();
44 final Optional
<ResumableUploadSpec
> resumableUploadSpec
= Optional
.empty();
45 return new SignalServiceAttachmentStream(streamDetails
.getStream(),
46 streamDetails
.getContentType(),
47 streamDetails
.getLength(),