]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/util/AttachmentUtils.java
Update libsignal-service
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / util / AttachmentUtils.java
index aadadf95b2922d35a8c88c91038d9ce744dc67d3..d06d87459c8738e2de035d80876be68f98035e03 100644 (file)
@@ -1,48 +1,48 @@
 package org.asamk.signal.manager.util;
 
-import org.asamk.signal.manager.AttachmentInvalidException;
-import org.whispersystems.libsignal.util.guava.Optional;
-import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
+import org.asamk.signal.manager.api.AttachmentInvalidException;
 import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
 import org.whispersystems.signalservice.api.util.StreamDetails;
 import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
 
-import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
 
 public class AttachmentUtils {
 
-    public static List<SignalServiceAttachment> getSignalServiceAttachments(List<String> attachments) throws AttachmentInvalidException {
-        List<SignalServiceAttachment> signalServiceAttachments = null;
-        if (attachments != null) {
-            signalServiceAttachments = new ArrayList<>(attachments.size());
-            for (var attachment : attachments) {
-                try {
-                    signalServiceAttachments.add(createAttachment(new File(attachment)));
-                } catch (IOException e) {
-                    throw new AttachmentInvalidException(attachment, e);
-                }
-            }
+    public static List<SignalServiceAttachmentStream> createAttachmentStreams(List<String> attachments) throws AttachmentInvalidException {
+        if (attachments == null) {
+            return null;
+        }
+        final var signalServiceAttachments = new ArrayList<SignalServiceAttachmentStream>(attachments.size());
+        for (var attachment : attachments) {
+            signalServiceAttachments.add(createAttachmentStream(attachment));
         }
         return signalServiceAttachments;
     }
 
-    public static SignalServiceAttachmentStream createAttachment(File attachmentFile) throws IOException {
-        final var streamDetails = Utils.createStreamDetailsFromFile(attachmentFile);
-        return createAttachment(streamDetails, Optional.of(attachmentFile.getName()));
+    public static SignalServiceAttachmentStream createAttachmentStream(String attachment) throws AttachmentInvalidException {
+        try {
+            final var streamDetails = Utils.createStreamDetails(attachment);
+
+            return createAttachmentStream(streamDetails.first(), streamDetails.second());
+        } catch (IOException e) {
+            throw new AttachmentInvalidException(attachment, e);
+        }
     }
 
-    public static SignalServiceAttachmentStream createAttachment(
+    public static SignalServiceAttachmentStream createAttachmentStream(
             StreamDetails streamDetails, Optional<String> name
     ) {
-        // TODO mabybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
+        // TODO maybe add a parameter to set the voiceNote, borderless, preview, width, height and caption option
         final var uploadTimestamp = System.currentTimeMillis();
-        Optional<byte[]> preview = Optional.absent();
-        Optional<String> caption = Optional.absent();
-        Optional<String> blurHash = Optional.absent();
-        final Optional<ResumableUploadSpec> resumableUploadSpec = Optional.absent();
+        Optional<byte[]> preview = Optional.empty();
+        Optional<String> caption = Optional.empty();
+        Optional<String> blurHash = Optional.empty();
+        final Optional<ResumableUploadSpec> resumableUploadSpec = Optional.empty();
         return new SignalServiceAttachmentStream(streamDetails.getStream(),
                 streamDetails.getContentType(),
                 streamDetails.getLength(),
@@ -50,6 +50,7 @@ public class AttachmentUtils {
                 false,
                 false,
                 false,
+                false,
                 preview,
                 0,
                 0,
@@ -58,6 +59,7 @@ public class AttachmentUtils {
                 blurHash,
                 null,
                 null,
-                resumableUploadSpec);
+                resumableUploadSpec,
+                UUID.randomUUID());
     }
 }