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(
17 ResumableUploadSpec resumableUploadSpec
18 ) throws AttachmentInvalidException
{
20 final var streamDetails
= Utils
.createStreamDetails(attachment
);
22 return createAttachmentStream(streamDetails
.first(), streamDetails
.second(), resumableUploadSpec
);
23 } catch (IOException e
) {
24 throw new AttachmentInvalidException(attachment
, e
);
28 public static SignalServiceAttachmentStream
createAttachmentStream(
29 StreamDetails streamDetails
,
30 Optional
<String
> name
,
31 ResumableUploadSpec resumableUploadSpec
32 ) throws ResumeLocationInvalidException
{
33 // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
34 final var uploadTimestamp
= System
.currentTimeMillis();
35 return SignalServiceAttachmentStream
.newStreamBuilder()
36 .withStream(streamDetails
.getStream())
37 .withContentType(streamDetails
.getContentType())
38 .withLength(streamDetails
.getLength())
39 .withFileName(name
.orElse(null))
40 .withUploadTimestamp(uploadTimestamp
)
41 .withResumableUploadSpec(resumableUploadSpec
)
42 .withUuid(UUID
.randomUUID())