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
;
12 import java
.util
.UUID
;
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(attachment
));
24 return signalServiceAttachments
;
27 public static SignalServiceAttachmentStream
createAttachmentStream(String attachment
) throws AttachmentInvalidException
{
29 final var streamDetails
= Utils
.createStreamDetails(attachment
);
31 return createAttachmentStream(streamDetails
.first(), streamDetails
.second());
32 } catch (IOException e
) {
33 throw new AttachmentInvalidException(attachment
, e
);
37 public static SignalServiceAttachmentStream
createAttachmentStream(
38 StreamDetails streamDetails
, Optional
<String
> name
40 // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
41 final var uploadTimestamp
= System
.currentTimeMillis();
42 Optional
<byte[]> preview
= Optional
.empty();
43 Optional
<String
> caption
= Optional
.empty();
44 Optional
<String
> blurHash
= Optional
.empty();
45 final Optional
<ResumableUploadSpec
> resumableUploadSpec
= Optional
.empty();
46 return new SignalServiceAttachmentStream(streamDetails
.getStream(),
47 streamDetails
.getContentType(),
48 streamDetails
.getLength(),