]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java
Add --bus-name option to use different D-Bus bus name
[signal-cli] / src / main / java / org / asamk / signal / dbus / DbusManagerImpl.java
index 985e2674d974c8030374c27eb5234a0175f49edf..f56a3ba48a8de57b61348bc983896e5e4ac30641 100644 (file)
@@ -1,7 +1,6 @@
 package org.asamk.signal.dbus;
 
 import org.asamk.Signal;
-import org.asamk.signal.DbusConfig;
 import org.asamk.signal.manager.Manager;
 import org.asamk.signal.manager.api.AlreadyReceivingException;
 import org.asamk.signal.manager.api.AttachmentInvalidException;
@@ -90,14 +89,16 @@ public class DbusManagerImpl implements Manager {
     private final Set<ReceiveMessageHandler> weakHandlers = new HashSet<>();
     private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>();
     private final List<Runnable> closedListeners = new ArrayList<>();
+    private final String busname;
     private DBusSigHandler<Signal.MessageReceivedV2> dbusMsgHandler;
     private DBusSigHandler<Signal.EditMessageReceived> dbusEditMsgHandler;
     private DBusSigHandler<Signal.ReceiptReceivedV2> dbusRcptHandler;
     private DBusSigHandler<Signal.SyncMessageReceivedV2> dbusSyncHandler;
 
-    public DbusManagerImpl(final Signal signal, DBusConnection connection) {
+    public DbusManagerImpl(final Signal signal, DBusConnection connection, final String busname) {
         this.signal = signal;
         this.connection = connection;
+        this.busname = busname;
     }
 
     @Override
@@ -121,7 +122,9 @@ public class DbusManagerImpl implements Manager {
     }
 
     @Override
-    public void updateAccountAttributes(final String deviceName) throws IOException {
+    public void updateAccountAttributes(
+            final String deviceName, final Boolean unrestrictedUnidentifiedSender
+    ) throws IOException {
         if (deviceName != null) {
             final var devicePath = signal.getThisDevice();
             getRemoteObject(devicePath, Signal.Device.class).Set("org.asamk.Signal.Device", "Name", deviceName);
@@ -397,7 +400,7 @@ public class DbusManagerImpl implements Manager {
 
     @Override
     public SendMessageResults sendMessage(
-            final Message message, final Set<RecipientIdentifier> recipients
+            final Message message, final Set<RecipientIdentifier> recipients, final boolean notifySelf
     ) throws IOException, AttachmentInvalidException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException {
         return handleMessage(recipients,
                 numbers -> signal.sendMessage(message.messageText(), message.attachments(), numbers),
@@ -668,7 +671,18 @@ public class DbusManagerImpl implements Manager {
             }
             return Recipient.newBuilder()
                     .withAddress(new RecipientAddress(null, n))
-                    .withContact(new Contact(contactName, null, null, 0, contactBlocked, false, false, false))
+                    .withContact(new Contact(contactName,
+                            null,
+                            null,
+                            null,
+                            0,
+                            0,
+                            false,
+                            contactBlocked,
+                            false,
+                            false,
+                            false,
+                            null))
                     .build();
         }).filter(Objects::nonNull).toList();
     }
@@ -807,7 +821,7 @@ public class DbusManagerImpl implements Manager {
 
     private <T extends DBusInterface> T getRemoteObject(final DBusPath path, final Class<T> type) {
         try {
-            return connection.getRemoteObject(DbusConfig.getBusname(), path.getPath(), type);
+            return connection.getRemoteObject(busname, path.getPath(), type);
         } catch (DBusException e) {
             throw new AssertionError(e);
         }
@@ -847,7 +861,7 @@ public class DbusManagerImpl implements Manager {
                                 Optional.empty(),
                                 Optional.empty(),
                                 List.of(),
-                                List.of(),
+                                getMentions(extras),
                                 List.of(),
                                 List.of())),
                         Optional.empty(),
@@ -891,7 +905,7 @@ public class DbusManagerImpl implements Manager {
                                         Optional.empty(),
                                         Optional.empty(),
                                         List.of(),
-                                        List.of(),
+                                        getMentions(extras),
                                         List.of(),
                                         List.of()))),
                         Optional.empty(),
@@ -968,7 +982,7 @@ public class DbusManagerImpl implements Manager {
                                         Optional.empty(),
                                         Optional.empty(),
                                         List.of(),
-                                        List.of(),
+                                        getMentions(extras),
                                         List.of(),
                                         List.of())),
                                 Optional.empty(),
@@ -1037,6 +1051,19 @@ public class DbusManagerImpl implements Manager {
         }).toList();
     }
 
+    private List<MessageEnvelope.Data.Mention> getMentions(final Map<String, Variant<?>> extras) {
+        if (!extras.containsKey("mentions")) {
+            return List.of();
+        }
+
+        final List<DBusMap<String, Variant<?>>> mentions = getValue(extras, "mentions");
+        return mentions.stream()
+                .map(a -> new MessageEnvelope.Data.Mention(new RecipientAddress(null, getValue(a, "recipient")),
+                        getValue(a, "start"),
+                        getValue(a, "length")))
+                .toList();
+    }
+
     @Override
     public InputStream retrieveAttachment(final String id) throws IOException {
         throw new UnsupportedOperationException();