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
.FileInputStream
;
10 import java
.io
.IOException
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.Optional
;
15 public class AttachmentUtils
{
17 public static List
<SignalServiceAttachmentStream
> createAttachmentStreams(List
<String
> attachments
) throws AttachmentInvalidException
{
18 if (attachments
== null) {
21 final var signalServiceAttachments
= new ArrayList
<SignalServiceAttachmentStream
>(attachments
.size());
22 for (var attachment
: attachments
) {
23 signalServiceAttachments
.add(createAttachmentStream(attachment
));
25 return signalServiceAttachments
;
28 public static SignalServiceAttachmentStream
createAttachmentStream(String attachment
) throws AttachmentInvalidException
{
30 final var streamDetails
= Utils
.createStreamDetails(attachment
);
32 return createAttachmentStream(streamDetails
.first(), streamDetails
.second());
33 } catch (IOException e
) {
34 throw new AttachmentInvalidException(attachment
, e
);
38 public static SignalServiceAttachmentStream
createAttachmentStream(
39 StreamDetails streamDetails
, Optional
<String
> name
41 // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
42 final var uploadTimestamp
= System
.currentTimeMillis();
43 Optional
<byte[]> preview
= Optional
.empty();
44 Optional
<String
> caption
= Optional
.empty();
45 Optional
<String
> blurHash
= Optional
.empty();
46 final Optional
<ResumableUploadSpec
> resumableUploadSpec
= Optional
.empty();
47 return new SignalServiceAttachmentStream(streamDetails
.getStream(),
48 streamDetails
.getContentType(),
49 streamDetails
.getLength(),