Extract getReceiveConfig to utils

This commit is contained in:
AsamK 2023-11-06 18:06:45 +01:00
parent 7b899d1853
commit 85b0647a3e
2 changed files with 13 additions and 8 deletions

View file

@ -9,7 +9,6 @@ import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.jsonrpc.SignalJsonRpcDispatcherHandler; import org.asamk.signal.jsonrpc.SignalJsonRpcDispatcherHandler;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.MultiAccountManager; import org.asamk.signal.manager.MultiAccountManager;
import org.asamk.signal.manager.api.ReceiveConfig;
import org.asamk.signal.output.JsonWriter; import org.asamk.signal.output.JsonWriter;
import org.asamk.signal.output.OutputWriter; import org.asamk.signal.output.OutputWriter;
import org.asamk.signal.util.IOUtils; import org.asamk.signal.util.IOUtils;
@ -20,6 +19,8 @@ import java.io.InputStreamReader;
import java.util.List; import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
import static org.asamk.signal.util.CommandUtil.getReceiveConfig;
public class JsonRpcDispatcherCommand implements LocalCommand, MultiLocalCommand { public class JsonRpcDispatcherCommand implements LocalCommand, MultiLocalCommand {
private final static Logger logger = LoggerFactory.getLogger(JsonRpcDispatcherCommand.class); private final static Logger logger = LoggerFactory.getLogger(JsonRpcDispatcherCommand.class);
@ -87,13 +88,6 @@ public class JsonRpcDispatcherCommand implements LocalCommand, MultiLocalCommand
handler.handleConnection(c); handler.handleConnection(c);
} }
private static ReceiveConfig getReceiveConfig(final Namespace ns) {
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
return new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
}
private static Supplier<String> getLineSupplier() { private static Supplier<String> getLineSupplier() {
return IOUtils.getLineSupplier(new InputStreamReader(System.in, IOUtils.getConsoleCharset())); return IOUtils.getLineSupplier(new InputStreamReader(System.in, IOUtils.getConsoleCharset()));
} }

View file

@ -1,5 +1,7 @@
package org.asamk.signal.util; package org.asamk.signal.util;
import net.sourceforge.argparse4j.inf.Namespace;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.CaptchaRequiredException;
@ -7,6 +9,7 @@ import org.asamk.signal.manager.api.GroupId;
import org.asamk.signal.manager.api.GroupIdFormatException; import org.asamk.signal.manager.api.GroupIdFormatException;
import org.asamk.signal.manager.api.InvalidNumberException; import org.asamk.signal.manager.api.InvalidNumberException;
import org.asamk.signal.manager.api.RateLimitException; import org.asamk.signal.manager.api.RateLimitException;
import org.asamk.signal.manager.api.ReceiveConfig;
import org.asamk.signal.manager.api.RecipientIdentifier; import org.asamk.signal.manager.api.RecipientIdentifier;
import java.util.Collection; import java.util.Collection;
@ -122,4 +125,12 @@ public class CommandUtil {
} }
return message; return message;
} }
public static ReceiveConfig getReceiveConfig(final Namespace ns) {
final var ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
final var ignoreStories = Boolean.TRUE.equals(ns.getBoolean("ignore-stories"));
final var sendReadReceipts = Boolean.TRUE.equals(ns.getBoolean("send-read-receipts"));
return new ReceiveConfig(ignoreAttachments, ignoreStories, sendReadReceipts);
}
} }