1 package org
.asamk
.signal
.manager
.util
;
3 import org
.asamk
.signal
.manager
.AttachmentInvalidException
;
4 import org
.whispersystems
.libsignal
.util
.guava
.Optional
;
5 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachment
;
6 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachmentStream
;
7 import org
.whispersystems
.signalservice
.api
.util
.StreamDetails
;
8 import org
.whispersystems
.signalservice
.internal
.push
.http
.ResumableUploadSpec
;
11 import java
.io
.IOException
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 public class AttachmentUtils
{
17 public static List
<SignalServiceAttachment
> getSignalServiceAttachments(List
<String
> attachments
) throws AttachmentInvalidException
{
18 List
<SignalServiceAttachment
> signalServiceAttachments
= null;
19 if (attachments
!= null) {
20 signalServiceAttachments
= new ArrayList
<>(attachments
.size());
21 for (String attachment
: attachments
) {
23 signalServiceAttachments
.add(createAttachment(new File(attachment
)));
24 } catch (IOException e
) {
25 throw new AttachmentInvalidException(attachment
, e
);
29 return signalServiceAttachments
;
32 public static SignalServiceAttachmentStream
createAttachment(File attachmentFile
) throws IOException
{
33 final StreamDetails streamDetails
= Utils
.createStreamDetailsFromFile(attachmentFile
);
34 return createAttachment(streamDetails
, Optional
.of(attachmentFile
.getName()));
37 public static SignalServiceAttachmentStream
createAttachment(
38 StreamDetails streamDetails
, Optional
<String
> name
40 // TODO mabybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
41 final long uploadTimestamp
= System
.currentTimeMillis();
42 Optional
<byte[]> preview
= Optional
.absent();
43 Optional
<String
> caption
= Optional
.absent();
44 Optional
<String
> blurHash
= Optional
.absent();
45 final Optional
<ResumableUploadSpec
> resumableUploadSpec
= Optional
.absent();
46 return new SignalServiceAttachmentStream(streamDetails
.getStream(),
47 streamDetails
.getContentType(),
48 streamDetails
.getLength(),