]> nmode's Git Repositories - signal-cli/blobdiff - lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java
Use Duration for timeout
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / ManagerImpl.java
index df757a8b92e26f4862d25b13688a7424a90b83de..cb9e473052fbb0572f0315ad480146e7c11b6332 100644 (file)
@@ -97,6 +97,7 @@ import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.security.SignatureException;
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -195,7 +196,7 @@ public class ManagerImpl implements Manager {
                 unidentifiedAccessHelper::getAccessFor,
                 this::resolveSignalServiceAddress);
         final GroupV2Helper groupV2Helper = new GroupV2Helper(profileHelper::getRecipientProfileKeyCredential,
-                this::getRecipientProfile,
+                profileHelper::getRecipientProfile,
                 account::getSelfRecipientId,
                 dependencies.getGroupsV2Operations(),
                 dependencies.getGroupsV2Api(),
@@ -207,6 +208,7 @@ public class ManagerImpl implements Manager {
                 account.getRecipientStore(),
                 this::handleIdentityFailure,
                 this::getGroupInfo,
+                profileHelper::getRecipientProfile,
                 this::refreshRegisteredUser);
         this.groupHelper = new GroupHelper(account,
                 dependencies,
@@ -245,7 +247,7 @@ public class ManagerImpl implements Manager {
                 contactHelper,
                 attachmentHelper,
                 syncHelper,
-                this::getRecipientProfile,
+                profileHelper::getRecipientProfile,
                 jobExecutor);
         this.identityHelper = new IdentityHelper(account,
                 dependencies,
@@ -1004,7 +1006,7 @@ public class ManagerImpl implements Manager {
             logger.debug("Starting receiving messages");
             while (!Thread.interrupted()) {
                 try {
-                    receiveMessagesInternal(1L, TimeUnit.HOURS, false, (envelope, e) -> {
+                    receiveMessagesInternal(Duration.ofMinutes(1), false, (envelope, e) -> {
                         synchronized (messageHandlers) {
                             Stream.concat(messageHandlers.stream(), weakHandlers.stream()).forEach(h -> {
                                 try {
@@ -1071,17 +1073,17 @@ public class ManagerImpl implements Manager {
     }
 
     @Override
-    public void receiveMessages(long timeout, TimeUnit unit, ReceiveMessageHandler handler) throws IOException {
-        receiveMessages(timeout, unit, true, handler);
+    public void receiveMessages(Duration timeout, ReceiveMessageHandler handler) throws IOException {
+        receiveMessages(timeout, true, handler);
     }
 
     @Override
     public void receiveMessages(ReceiveMessageHandler handler) throws IOException {
-        receiveMessages(1L, TimeUnit.HOURS, false, handler);
+        receiveMessages(Duration.ofMinutes(1), false, handler);
     }
 
     private void receiveMessages(
-            long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
+            Duration timeout, boolean returnOnTimeout, ReceiveMessageHandler handler
     ) throws IOException {
         if (isReceiving()) {
             throw new IllegalStateException("Already receiving message.");
@@ -1089,7 +1091,7 @@ public class ManagerImpl implements Manager {
         isReceivingSynchronous = true;
         receiveThread = Thread.currentThread();
         try {
-            receiveMessagesInternal(timeout, unit, returnOnTimeout, handler);
+            receiveMessagesInternal(timeout, returnOnTimeout, handler);
         } finally {
             receiveThread = null;
             hasCaughtUpWithOldMessages = false;
@@ -1098,7 +1100,7 @@ public class ManagerImpl implements Manager {
     }
 
     private void receiveMessagesInternal(
-            long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
+            Duration timeout, boolean returnOnTimeout, ReceiveMessageHandler handler
     ) throws IOException {
         retryFailedReceivedMessages(handler);
 
@@ -1127,7 +1129,7 @@ public class ManagerImpl implements Manager {
             }
             logger.debug("Checking for new message from server");
             try {
-                var result = signalWebSocket.readOrEmpty(unit.toMillis(timeout), envelope1 -> {
+                var result = signalWebSocket.readOrEmpty(timeout.toMillis(), envelope1 -> {
                     final var recipientId = envelope1.hasSourceUuid()
                             ? resolveRecipient(envelope1.getSourceAddress())
                             : null;