]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/util/AttachmentUtils.java
Update dependencies
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / util / AttachmentUtils.java
1 package org.asamk.signal.manager.util;
2
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;
8
9 import java.io.IOException;
10 import java.util.Optional;
11 import java.util.UUID;
12
13 public class AttachmentUtils {
14
15 public static SignalServiceAttachmentStream createAttachmentStream(
16 String attachment, ResumableUploadSpec resumableUploadSpec
17 ) throws AttachmentInvalidException {
18 try {
19 final var streamDetails = Utils.createStreamDetails(attachment);
20
21 return createAttachmentStream(streamDetails.first(), streamDetails.second(), resumableUploadSpec);
22 } catch (IOException e) {
23 throw new AttachmentInvalidException(attachment, e);
24 }
25 }
26
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())
40 .build();
41 }
42 }