]> nmode's Git Repositories - signal-cli/commitdiff
Add setIgnoreAttachments method
authorAsamK <asamk@gmx.de>
Thu, 21 Oct 2021 19:01:48 +0000 (21:01 +0200)
committerAsamK <asamk@gmx.de>
Thu, 21 Oct 2021 19:01:48 +0000 (21:01 +0200)
lib/src/main/java/org/asamk/signal/manager/Manager.java
lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
src/main/java/org/asamk/signal/commands/DaemonCommand.java
src/main/java/org/asamk/signal/commands/JsonRpcDispatcherCommand.java
src/main/java/org/asamk/signal/commands/ReceiveCommand.java
src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java

index 733e3dccc285fe831e966e03c646ef5c207fa1c2..f70c4e29d33766a405d15fd79e2de413f10359a1 100644 (file)
@@ -194,13 +194,11 @@ public interface Manager extends Closeable {
     void requestAllSyncData() throws IOException;
 
     void receiveMessages(
     void requestAllSyncData() throws IOException;
 
     void receiveMessages(
-            long timeout,
-            TimeUnit unit,
-            boolean returnOnTimeout,
-            boolean ignoreAttachments,
-            ReceiveMessageHandler handler
+            long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
     ) throws IOException;
 
     ) throws IOException;
 
+    void setIgnoreAttachments(boolean ignoreAttachments);
+
     boolean hasCaughtUpWithOldMessages();
 
     boolean isContactBlocked(RecipientIdentifier.Single recipient);
     boolean hasCaughtUpWithOldMessages();
 
     boolean isContactBlocked(RecipientIdentifier.Single recipient);
index cc90de5ca049ff0aa3f7e6c184a72be2cecd7050..bec7f52143cf7c902ef2545545f18ca47567c1f3 100644 (file)
@@ -135,6 +135,7 @@ public class ManagerImpl implements Manager {
 
     private final Context context;
     private boolean hasCaughtUpWithOldMessages = false;
 
     private final Context context;
     private boolean hasCaughtUpWithOldMessages = false;
+    private boolean ignoreAttachments = false;
 
     ManagerImpl(
             SignalAccount account,
 
     ManagerImpl(
             SignalAccount account,
@@ -824,10 +825,10 @@ public class ManagerImpl implements Manager {
         return registeredUsers;
     }
 
         return registeredUsers;
     }
 
-    private void retryFailedReceivedMessages(ReceiveMessageHandler handler, boolean ignoreAttachments) {
+    private void retryFailedReceivedMessages(ReceiveMessageHandler handler) {
         Set<HandleAction> queuedActions = new HashSet<>();
         for (var cachedMessage : account.getMessageCache().getCachedMessages()) {
         Set<HandleAction> queuedActions = new HashSet<>();
         for (var cachedMessage : account.getMessageCache().getCachedMessages()) {
-            var actions = retryFailedReceivedMessage(handler, ignoreAttachments, cachedMessage);
+            var actions = retryFailedReceivedMessage(handler, cachedMessage);
             if (actions != null) {
                 queuedActions.addAll(actions);
             }
             if (actions != null) {
                 queuedActions.addAll(actions);
             }
@@ -836,7 +837,7 @@ public class ManagerImpl implements Manager {
     }
 
     private List<HandleAction> retryFailedReceivedMessage(
     }
 
     private List<HandleAction> retryFailedReceivedMessage(
-            final ReceiveMessageHandler handler, final boolean ignoreAttachments, final CachedMessage cachedMessage
+            final ReceiveMessageHandler handler, final CachedMessage cachedMessage
     ) {
         var envelope = cachedMessage.loadEnvelope();
         if (envelope == null) {
     ) {
         var envelope = cachedMessage.loadEnvelope();
         if (envelope == null) {
@@ -873,13 +874,9 @@ public class ManagerImpl implements Manager {
 
     @Override
     public void receiveMessages(
 
     @Override
     public void receiveMessages(
-            long timeout,
-            TimeUnit unit,
-            boolean returnOnTimeout,
-            boolean ignoreAttachments,
-            ReceiveMessageHandler handler
+            long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
     ) throws IOException {
     ) throws IOException {
-        retryFailedReceivedMessages(handler, ignoreAttachments);
+        retryFailedReceivedMessages(handler);
 
         Set<HandleAction> queuedActions = new HashSet<>();
 
 
         Set<HandleAction> queuedActions = new HashSet<>();
 
@@ -980,6 +977,11 @@ public class ManagerImpl implements Manager {
         queuedActions.clear();
     }
 
         queuedActions.clear();
     }
 
+    @Override
+    public void setIgnoreAttachments(final boolean ignoreAttachments) {
+        this.ignoreAttachments = ignoreAttachments;
+    }
+
     @Override
     public boolean hasCaughtUpWithOldMessages() {
         return hasCaughtUpWithOldMessages;
     @Override
     public boolean hasCaughtUpWithOldMessages() {
         return hasCaughtUpWithOldMessages;
index 02063b8721fbc7bea4de1ceb08ca0c948f3ab329..9997f56a9e059325658e3b4d5ab81196224bc73f 100644 (file)
@@ -55,6 +55,7 @@ public class DaemonCommand implements MultiLocalCommand {
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
         boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
         boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
+        m.setIgnoreAttachments(ignoreAttachments);
 
         DBusConnection.DBusBusType busType;
         if (Boolean.TRUE.equals(ns.getBoolean("system"))) {
 
         DBusConnection.DBusBusType busType;
         if (Boolean.TRUE.equals(ns.getBoolean("system"))) {
@@ -65,7 +66,7 @@ public class DaemonCommand implements MultiLocalCommand {
 
         try (var conn = DBusConnection.getConnection(busType)) {
             var objectPath = DbusConfig.getObjectPath();
 
         try (var conn = DBusConnection.getConnection(busType)) {
             var objectPath = DbusConfig.getObjectPath();
-            var t = run(conn, objectPath, m, outputWriter, ignoreAttachments);
+            var t = run(conn, objectPath, m, outputWriter);
 
             conn.requestBusName(DbusConfig.getBusname());
 
 
             conn.requestBusName(DbusConfig.getBusname());
 
@@ -94,9 +95,10 @@ public class DaemonCommand implements MultiLocalCommand {
 
         try (var conn = DBusConnection.getConnection(busType)) {
             final var signalControl = new DbusSignalControlImpl(c, m -> {
 
         try (var conn = DBusConnection.getConnection(busType)) {
             final var signalControl = new DbusSignalControlImpl(c, m -> {
+                m.setIgnoreAttachments(ignoreAttachments);
                 try {
                     final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber());
                 try {
                     final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber());
-                    return run(conn, objectPath, m, outputWriter, ignoreAttachments);
+                    return run(conn, objectPath, m, outputWriter);
                 } catch (DBusException e) {
                     logger.error("Failed to export object", e);
                     return null;
                 } catch (DBusException e) {
                     logger.error("Failed to export object", e);
                     return null;
@@ -118,7 +120,7 @@ public class DaemonCommand implements MultiLocalCommand {
     }
 
     private Thread run(
     }
 
     private Thread run(
-            DBusConnection conn, String objectPath, Manager m, OutputWriter outputWriter, boolean ignoreAttachments
+            DBusConnection conn, String objectPath, Manager m, OutputWriter outputWriter
     ) throws DBusException {
         final var signal = new DbusSignalImpl(m, conn, objectPath);
         conn.exportObject(signal);
     ) throws DBusException {
         final var signal = new DbusSignalImpl(m, conn, objectPath);
         conn.exportObject(signal);
@@ -133,7 +135,7 @@ public class DaemonCommand implements MultiLocalCommand {
                     final var receiveMessageHandler = outputWriter instanceof JsonWriter
                             ? new JsonDbusReceiveMessageHandler(m, (JsonWriter) outputWriter, conn, objectPath)
                             : new DbusReceiveMessageHandler(m, (PlainTextWriter) outputWriter, conn, objectPath);
                     final var receiveMessageHandler = outputWriter instanceof JsonWriter
                             ? new JsonDbusReceiveMessageHandler(m, (JsonWriter) outputWriter, conn, objectPath)
                             : new DbusReceiveMessageHandler(m, (PlainTextWriter) outputWriter, conn, objectPath);
-                    m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, receiveMessageHandler);
+                    m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
                     break;
                 } catch (IOException e) {
                     logger.warn("Receiving messages failed, retrying", e);
                     break;
                 } catch (IOException e) {
                     logger.warn("Receiving messages failed, retrying", e);
index 9af67322197ab1335574b66226463b2445d67941..349bd0c415771b93b6ef8cc5cffcc2fba1e781fc 100644 (file)
@@ -66,6 +66,7 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
         final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
             final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
         final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
+        m.setIgnoreAttachments(ignoreAttachments);
 
         final var objectMapper = Util.createJsonObjectMapper();
         final var jsonRpcSender = new JsonRpcSender((JsonWriter) outputWriter);
 
         final var objectMapper = Util.createJsonObjectMapper();
         final var jsonRpcSender = new JsonRpcSender((JsonWriter) outputWriter);
@@ -73,7 +74,7 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
         final var receiveThread = receiveMessages(s -> jsonRpcSender.sendRequest(JsonRpcRequest.forNotification(
                 "receive",
                 objectMapper.valueToTree(s),
         final var receiveThread = receiveMessages(s -> jsonRpcSender.sendRequest(JsonRpcRequest.forNotification(
                 "receive",
                 objectMapper.valueToTree(s),
-                null)), m, ignoreAttachments);
+                null)), m);
 
         // Maybe this should be handled inside the Manager
         while (!m.hasCaughtUpWithOldMessages()) {
 
         // Maybe this should be handled inside the Manager
         while (!m.hasCaughtUpWithOldMessages()) {
@@ -167,14 +168,12 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
         command.handleCommand(requestParams, m, outputWriter);
     }
 
         command.handleCommand(requestParams, m, outputWriter);
     }
 
-    private Thread receiveMessages(
-            JsonWriter jsonWriter, Manager m, boolean ignoreAttachments
-    ) {
+    private Thread receiveMessages(JsonWriter jsonWriter, Manager m) {
         final var thread = new Thread(() -> {
             while (!Thread.interrupted()) {
                 try {
                     final var receiveMessageHandler = new JsonReceiveMessageHandler(m, jsonWriter);
         final var thread = new Thread(() -> {
             while (!Thread.interrupted()) {
                 try {
                     final var receiveMessageHandler = new JsonReceiveMessageHandler(m, jsonWriter);
-                    m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, receiveMessageHandler);
+                    m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
                     break;
                 } catch (IOException e) {
                     logger.warn("Receiving messages failed, retrying", e);
                     break;
                 } catch (IOException e) {
                     logger.warn("Receiving messages failed, retrying", e);
index 4686f26dbcabecc409898ecf56d29fb060badaa9..b4797be3528611ef7a5248a404b2f27dc2e80c63 100644 (file)
@@ -148,14 +148,11 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
             timeout = 3600;
         }
         boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
             timeout = 3600;
         }
         boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
+        m.setIgnoreAttachments(ignoreAttachments);
         try {
             final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
                     (JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
         try {
             final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
                     (JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
-            m.receiveMessages((long) (timeout * 1000),
-                    TimeUnit.MILLISECONDS,
-                    returnOnTimeout,
-                    ignoreAttachments,
-                    handler);
+            m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, handler);
         } catch (IOException e) {
             throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
         }
         } catch (IOException e) {
             throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
         }
index 59422e6922354ad01b454e2976dcbbb00ea6f11c..93d368881a68465c0fef0f5abac2612623135ff2 100644 (file)
@@ -425,15 +425,16 @@ public class DbusManagerImpl implements Manager {
 
     @Override
     public void receiveMessages(
 
     @Override
     public void receiveMessages(
-            final long timeout,
-            final TimeUnit unit,
-            final boolean returnOnTimeout,
-            final boolean ignoreAttachments,
-            final ReceiveMessageHandler handler
+            final long timeout, final TimeUnit unit, final boolean returnOnTimeout, final ReceiveMessageHandler handler
     ) throws IOException {
         throw new UnsupportedOperationException();
     }
 
     ) throws IOException {
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public void setIgnoreAttachments(final boolean ignoreAttachments) {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     public boolean hasCaughtUpWithOldMessages() {
         throw new UnsupportedOperationException();
     @Override
     public boolean hasCaughtUpWithOldMessages() {
         throw new UnsupportedOperationException();