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
;
8 import java
.io
.IOException
;
9 import java
.util
.ArrayList
;
10 import java
.util
.List
;
11 import java
.util
.Optional
;
13 public class AttachmentUtils
{
15 public static List
<SignalServiceAttachmentStream
> createAttachmentStreams(List
<String
> attachments
) throws AttachmentInvalidException
{
16 if (attachments
== null) {
19 final var signalServiceAttachments
= new ArrayList
<SignalServiceAttachmentStream
>(attachments
.size());
20 for (var attachment
: attachments
) {
21 signalServiceAttachments
.add(createAttachmentStream(attachment
));
23 return signalServiceAttachments
;
26 public static SignalServiceAttachmentStream
createAttachmentStream(String attachment
) throws AttachmentInvalidException
{
28 final var streamDetails
= Utils
.createStreamDetails(attachment
);
30 return createAttachmentStream(streamDetails
.first(), streamDetails
.second());
31 } catch (IOException e
) {
32 throw new AttachmentInvalidException(attachment
, 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(),