1 package org
.asamk
.signal
.manager
.util
;
3 import org
.asamk
.signal
.manager
.api
.AttachmentInvalidException
;
4 import org
.signal
.protos
.resumableuploads
.ResumableUpload
;
5 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceAttachmentStream
;
6 import org
.whispersystems
.signalservice
.api
.push
.exceptions
.ResumeLocationInvalidException
;
7 import org
.whispersystems
.signalservice
.api
.util
.StreamDetails
;
8 import org
.whispersystems
.signalservice
.internal
.push
.http
.ResumableUploadSpec
;
10 import java
.io
.IOException
;
11 import java
.util
.Optional
;
12 import java
.util
.UUID
;
14 public class AttachmentUtils
{
16 public static SignalServiceAttachmentStream
createAttachmentStream(
17 String attachment
, ResumableUpload resumableUpload
18 ) throws AttachmentInvalidException
{
20 final var streamDetails
= Utils
.createStreamDetails(attachment
);
22 return createAttachmentStream(streamDetails
.first(), streamDetails
.second(), resumableUpload
);
23 } catch (IOException e
) {
24 throw new AttachmentInvalidException(attachment
, e
);
28 public static SignalServiceAttachmentStream
createAttachmentStream(
29 StreamDetails streamDetails
, Optional
<String
> name
, ResumableUpload resumableUpload
30 ) throws ResumeLocationInvalidException
{
31 // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
32 final var uploadTimestamp
= System
.currentTimeMillis();
33 final var resumableUploadSpec
= ResumableUploadSpec
.from(resumableUpload
);
34 return SignalServiceAttachmentStream
.newStreamBuilder()
35 .withStream(streamDetails
.getStream())
36 .withContentType(streamDetails
.getContentType())
37 .withLength(streamDetails
.getLength())
38 .withFileName(name
.orElse(null))
39 .withUploadTimestamp(uploadTimestamp
)
40 .withResumableUploadSpec(resumableUploadSpec
)
41 .withUuid(UUID
.randomUUID())