]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/util/AttachmentUtils.java
Update libsignal-service-java
[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,
17 ResumableUploadSpec resumableUploadSpec
18 ) throws AttachmentInvalidException {
19 try {
20 final var streamDetails = Utils.createStreamDetails(attachment);
21
22 return createAttachmentStream(streamDetails.first(), streamDetails.second(), resumableUploadSpec);
23 } catch (IOException e) {
24 throw new AttachmentInvalidException(attachment, e);
25 }
26 }
27
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())
43 .build();
44 }
45 }