]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/dbus/DbusReceiveMessageHandler.java
Add sendPaymentNotification dbus method
[signal-cli] / src / main / java / org / asamk / signal / dbus / DbusReceiveMessageHandler.java
index da79f5bface03b9c0fa693ec9c2dc793fcfd3367..dcea2bf1e674733d16fa7f77e2dd87d0d2260622 100644 (file)
@@ -14,7 +14,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler {
 
@@ -80,27 +79,29 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
             if (syncMessage.sent().isPresent()) {
                 var transcript = syncMessage.sent().get();
 
-                if (transcript.destination().isPresent() || transcript.message().groupContext().isPresent()) {
-                    var message = transcript.message();
-                    var groupId = message.groupContext()
-                            .map(MessageEnvelope.Data.GroupContext::groupId)
-                            .map(GroupId::serialize)
-                            .orElseGet(() -> new byte[0]);
-
-                    conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
-                            transcript.message().timestamp(),
-                            senderString,
-                            transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
-                            groupId,
-                            message.body().orElse(""),
-                            getAttachments(message)));
-                    conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
-                            transcript.message().timestamp(),
-                            senderString,
-                            transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
-                            groupId,
-                            message.body().orElse(""),
-                            getMessageExtras(message)));
+                if (transcript.message().isPresent()) {
+                    final var dataMessage = transcript.message().get();
+                    if (transcript.destination().isPresent() || dataMessage.groupContext().isPresent()) {
+                        var groupId = dataMessage.groupContext()
+                                .map(MessageEnvelope.Data.GroupContext::groupId)
+                                .map(GroupId::serialize)
+                                .orElseGet(() -> new byte[0]);
+
+                        conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
+                                dataMessage.timestamp(),
+                                senderString,
+                                transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
+                                groupId,
+                                dataMessage.body().orElse(""),
+                                getAttachments(dataMessage)));
+                        conn.sendMessage(new Signal.SyncMessageReceivedV2(objectPath,
+                                dataMessage.timestamp(),
+                                senderString,
+                                transcript.destination().map(RecipientAddress::getLegacyIdentifier).orElse(""),
+                                groupId,
+                                dataMessage.body().orElse(""),
+                                getMessageExtras(dataMessage)));
+                    }
                 }
             }
         }
@@ -126,11 +127,11 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
                     .stream()
                     .filter(a -> a.id().isPresent())
                     .map(this::getAttachmentMap)
-                    .collect(Collectors.toList());
+                    .toList();
             extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
         }
         if (message.mentions().size() > 0) {
-            var mentions = message.mentions().stream().map(this::getMentionMap).collect(Collectors.toList());
+            var mentions = message.mentions().stream().map(this::getMentionMap).toList();
             extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
         }
         extras.put("expiresInSeconds", new Variant<>(message.expiresInSeconds()));
@@ -163,7 +164,10 @@ public class DbusReceiveMessageHandler implements Manager.ReceiveMessageHandler
     }
 
     private Map<String, Variant<? extends Serializable>> getStickerMap(final MessageEnvelope.Data.Sticker sticker) {
-        return Map.of("packId", new Variant<>(sticker.packId()), "stickerId", new Variant<>(sticker.stickerId()));
+        return Map.of("packId",
+                new Variant<>(sticker.packId().serialize()),
+                "stickerId",
+                new Variant<>(sticker.stickerId()));
     }
 
     private Map<String, Variant<?>> getReactionMap(final MessageEnvelope.Data.Reaction reaction) {