]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/api/MessageEnvelope.java
Update libsignal-service
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / api / MessageEnvelope.java
index 00abd93e74ffe37caead69418ef012e534ed2ba4..aefaa800333000db7d557fa3eafd6f917cbc5736 100644 (file)
@@ -32,8 +32,10 @@ import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptM
 import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
 import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage;
 import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
+import org.whispersystems.signalservice.api.push.ServiceId;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
@@ -139,7 +141,9 @@ public record MessageEnvelope(
                     dataMessage.isProfileKeyUpdate(),
                     dataMessage.getProfileKey().isPresent(),
                     dataMessage.getReaction().map(r -> Reaction.from(r, recipientResolver, addressResolver)),
-                    dataMessage.getQuote().map(q -> Quote.from(q, recipientResolver, addressResolver, fileProvider)),
+                    dataMessage.getQuote()
+                            .filter(q -> q.getAuthor() != null && q.getAuthor().isValid())
+                            .map(q -> Quote.from(q, recipientResolver, addressResolver, fileProvider)),
                     dataMessage.getPayment().map(p -> p.getPaymentNotification().isPresent() ? Payment.from(p) : null),
                     dataMessage.getAttachments()
                             .map(a -> a.stream().map(as -> Attachment.from(as, fileProvider)).toList())
@@ -234,7 +238,7 @@ public record MessageEnvelope(
                 return new Quote(quote.getId(),
                         addressResolver.resolveRecipientAddress(recipientResolver.resolveRecipient(quote.getAuthor()))
                                 .toApiRecipientAddress(),
-                        Optional.ofNullable(quote.getText()),
+                        Optional.of(quote.getText()),
                         quote.getMentions() == null
                                 ? List.of()
                                 : quote.getMentions()
@@ -291,9 +295,9 @@ public record MessageEnvelope(
                 boolean isBorderless
         ) {
 
-            static Attachment from(SignalServiceAttachment attachment, AttachmentFileProvider fileProvider) {
-                if (attachment.isPointer()) {
-                    final var a = attachment.asPointer();
+            static Attachment from(SignalServiceAttachment signalAttachment, AttachmentFileProvider fileProvider) {
+                if (signalAttachment.isPointer()) {
+                    final var a = signalAttachment.asPointer();
                     final var attachmentFile = fileProvider.getFile(a);
                     return new Attachment(Optional.of(attachmentFile.getName()),
                             Optional.of(attachmentFile),
@@ -310,21 +314,26 @@ public record MessageEnvelope(
                             a.isGif(),
                             a.isBorderless());
                 } else {
-                    final var a = attachment.asStream();
-                    return new Attachment(Optional.empty(),
-                            Optional.empty(),
-                            a.getFileName(),
-                            a.getContentType(),
-                            a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
-                            Optional.of(a.getLength()),
-                            a.getPreview(),
-                            Optional.empty(),
-                            a.getCaption(),
-                            a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
-                            a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
-                            a.getVoiceNote(),
-                            a.isGif(),
-                            a.isBorderless());
+                    Attachment attachment = null;
+                    try (final var a = signalAttachment.asStream()) {
+                        attachment = new Attachment(Optional.empty(),
+                                Optional.empty(),
+                                a.getFileName(),
+                                a.getContentType(),
+                                a.getUploadTimestamp() == 0 ? Optional.empty() : Optional.of(a.getUploadTimestamp()),
+                                Optional.of(a.getLength()),
+                                a.getPreview(),
+                                Optional.empty(),
+                                a.getCaption(),
+                                a.getWidth() == 0 ? Optional.empty() : Optional.of(a.getWidth()),
+                                a.getHeight() == 0 ? Optional.empty() : Optional.of(a.getHeight()),
+                                a.getVoiceNote(),
+                                a.isGif(),
+                                a.isBorderless());
+                        return attachment;
+                    } catch (IOException e) {
+                        return attachment;
+                    }
                 }
             }
 
@@ -381,7 +390,7 @@ public record MessageEnvelope(
             }
 
             public record Name(
-                    Optional<String> display,
+                    Optional<String> nickname,
                     Optional<String> given,
                     Optional<String> family,
                     Optional<String> prefix,
@@ -390,7 +399,7 @@ public record MessageEnvelope(
             ) {
 
                 static Name from(org.whispersystems.signalservice.api.messages.shared.SharedContact.Name name) {
-                    return new Name(name.getDisplay(),
+                    return new Name(name.getNickname(),
                             name.getGiven(),
                             name.getFamily(),
                             name.getPrefix(),
@@ -472,15 +481,15 @@ public record MessageEnvelope(
             ) {
 
                 static Address from(org.whispersystems.signalservice.api.messages.shared.SharedContact.PostalAddress address) {
-                    return new Address(Address.Type.from(address.getType()),
-                            address.getLabel(),
-                            address.getLabel(),
-                            address.getLabel(),
-                            address.getLabel(),
-                            address.getLabel(),
-                            address.getLabel(),
+                    return new Address(Type.from(address.getType()),
                             address.getLabel(),
-                            address.getLabel());
+                            address.getStreet(),
+                            address.getPobox(),
+                            address.getNeighborhood(),
+                            address.getCity(),
+                            address.getRegion(),
+                            address.getPostcode(),
+                            address.getCountry());
                 }
 
                 public enum Type {
@@ -681,7 +690,9 @@ public record MessageEnvelope(
                 DELETE,
                 BLOCK,
                 BLOCK_AND_DELETE,
-                UNBLOCK_AND_ACCEPT;
+                UNBLOCK_AND_ACCEPT,
+                SPAM,
+                BLOCK_AND_SPAM;
 
                 static Type from(MessageRequestResponseMessage.Type type) {
                     return switch (type) {
@@ -691,6 +702,8 @@ public record MessageEnvelope(
                         case BLOCK -> BLOCK;
                         case BLOCK_AND_DELETE -> BLOCK_AND_DELETE;
                         case UNBLOCK_AND_ACCEPT -> UNBLOCK_AND_ACCEPT;
+                        case SPAM -> SPAM;
+                        case BLOCK_AND_SPAM -> BLOCK_AND_SPAM;
                     };
                 }
             }
@@ -707,7 +720,6 @@ public record MessageEnvelope(
             Optional<Busy> busy,
             List<IceUpdate> iceUpdate,
             Optional<Opaque> opaque,
-            boolean isMultiRing,
             boolean isUrgent
     ) {
 
@@ -723,17 +735,13 @@ public record MessageEnvelope(
                             .map(m -> m.stream().map(IceUpdate::from).toList())
                             .orElse(List.of()),
                     callMessage.getOpaqueMessage().map(Opaque::from),
-                    callMessage.isMultiRing(),
                     callMessage.isUrgent());
         }
 
-        public record Offer(long id, String sdp, Type type, byte[] opaque) {
+        public record Offer(long id, Type type, byte[] opaque) {
 
             static Offer from(OfferMessage offerMessage) {
-                return new Offer(offerMessage.getId(),
-                        offerMessage.getSdp(),
-                        Type.from(offerMessage.getType()),
-                        offerMessage.getOpaque());
+                return new Offer(offerMessage.getId(), Type.from(offerMessage.getType()), offerMessage.getOpaque());
             }
 
             public enum Type {
@@ -749,10 +757,10 @@ public record MessageEnvelope(
             }
         }
 
-        public record Answer(long id, String sdp, byte[] opaque) {
+        public record Answer(long id, byte[] opaque) {
 
             static Answer from(AnswerMessage answerMessage) {
-                return new Answer(answerMessage.getId(), answerMessage.getSdp(), answerMessage.getOpaque());
+                return new Answer(answerMessage.getId(), answerMessage.getOpaque());
             }
         }
 
@@ -790,10 +798,10 @@ public record MessageEnvelope(
             }
         }
 
-        public record IceUpdate(long id, String sdp, byte[] opaque) {
+        public record IceUpdate(long id, byte[] opaque) {
 
             static IceUpdate from(IceUpdateMessage iceUpdateMessage) {
-                return new IceUpdate(iceUpdateMessage.getId(), iceUpdateMessage.getSdp(), iceUpdateMessage.getOpaque());
+                return new IceUpdate(iceUpdateMessage.getId(), iceUpdateMessage.getOpaque());
             }
         }
 
@@ -896,8 +904,9 @@ public record MessageEnvelope(
             final AttachmentFileProvider fileProvider,
             Exception exception
     ) {
-        final var source = !envelope.isUnidentifiedSender() && envelope.hasSourceServiceId()
-                ? recipientResolver.resolveRecipient(envelope.getSourceAddress())
+        final var serviceId = envelope.getSourceServiceId().map(ServiceId::parseOrNull).orElse(null);
+        final var source = !envelope.isUnidentifiedSender() && serviceId != null
+                ? recipientResolver.resolveRecipient(serviceId)
                 : envelope.isUnidentifiedSender() && content != null
                         ? recipientResolver.resolveRecipient(content.getSender())
                         : exception instanceof ProtocolException e