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
.push
.exceptions
.ResumeLocationInvalidException
;
6 import org
.whispersystems
.signalservice
.api
.util
.StreamDetails
;
7 import org
.whispersystems
.signalservice
.internal
.push
.http
.ResumableUploadSpec
;
9 import java
.io
.IOException
;
10 import java
.util
.Optional
;
11 import java
.util
.UUID
;
13 public class AttachmentUtils
{
15 public static SignalServiceAttachmentStream
createAttachmentStream(
16 String attachment
, ResumableUploadSpec resumableUploadSpec
17 ) throws AttachmentInvalidException
{
19 final var streamDetails
= Utils
.createStreamDetails(attachment
);
21 return createAttachmentStream(streamDetails
.first(), streamDetails
.second(), resumableUploadSpec
);
22 } catch (IOException e
) {
23 throw new AttachmentInvalidException(attachment
, e
);
27 public static SignalServiceAttachmentStream
createAttachmentStream(
28 StreamDetails streamDetails
, Optional
<String
> name
, ResumableUploadSpec resumableUploadSpec
29 ) throws ResumeLocationInvalidException
{
30 // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
31 final var uploadTimestamp
= System
.currentTimeMillis();
32 return SignalServiceAttachmentStream
.newStreamBuilder()
33 .withStream(streamDetails
.getStream())
34 .withContentType(streamDetails
.getContentType())
35 .withLength(streamDetails
.getLength())
36 .withFileName(name
.orElse(null))
37 .withUploadTimestamp(uploadTimestamp
)
38 .withResumableUploadSpec(resumableUploadSpec
)
39 .withUuid(UUID
.randomUUID())