mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Split receiveMessages method
This commit is contained in:
parent
430c155f7e
commit
5c389c875d
6 changed files with 32 additions and 15 deletions
|
@ -193,9 +193,15 @@ public interface Manager extends Closeable {
|
|||
|
||||
void requestAllSyncData() throws IOException;
|
||||
|
||||
void receiveMessages(
|
||||
long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
|
||||
) throws IOException;
|
||||
/**
|
||||
* Receive new messages from server, returns if no new message arrive in a timespan of timeout.
|
||||
*/
|
||||
void receiveMessages(long timeout, TimeUnit unit, ReceiveMessageHandler handler) throws IOException;
|
||||
|
||||
/**
|
||||
* Receive new messages from server, returns only if the thread is interrupted.
|
||||
*/
|
||||
void receiveMessages(ReceiveMessageHandler handler) throws IOException;
|
||||
|
||||
void setIgnoreAttachments(boolean ignoreAttachments);
|
||||
|
||||
|
|
|
@ -873,7 +873,16 @@ public class ManagerImpl implements Manager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void receiveMessages(
|
||||
public void receiveMessages(long timeout, TimeUnit unit, ReceiveMessageHandler handler) throws IOException {
|
||||
receiveMessages(timeout, unit, true, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveMessages(ReceiveMessageHandler handler) throws IOException {
|
||||
receiveMessages(1L, TimeUnit.HOURS, false, handler);
|
||||
}
|
||||
|
||||
private void receiveMessages(
|
||||
long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
|
||||
) throws IOException {
|
||||
retryFailedReceivedMessages(handler);
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DaemonCommand implements MultiLocalCommand {
|
||||
|
||||
|
@ -135,7 +134,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);
|
||||
m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
|
||||
m.receiveMessages(receiveMessageHandler);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
logger.warn("Receiving messages failed, retrying", e);
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class JsonRpcDispatcherCommand implements LocalCommand {
|
||||
|
||||
|
@ -173,7 +172,7 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
|
|||
while (!Thread.interrupted()) {
|
||||
try {
|
||||
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, jsonWriter);
|
||||
m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
|
||||
m.receiveMessages(receiveMessageHandler);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
logger.warn("Receiving messages failed, retrying", e);
|
||||
|
|
|
@ -142,17 +142,16 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
|||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
double timeout = ns.getDouble("timeout");
|
||||
var returnOnTimeout = true;
|
||||
if (timeout < 0) {
|
||||
returnOnTimeout = false;
|
||||
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);
|
||||
m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, handler);
|
||||
if (timeout < 0) {
|
||||
m.receiveMessages(handler);
|
||||
} else {
|
||||
m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, handler);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
|
||||
}
|
||||
|
|
|
@ -423,9 +423,14 @@ public class DbusManagerImpl implements Manager {
|
|||
signal.sendSyncRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveMessages(final ReceiveMessageHandler handler) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveMessages(
|
||||
final long timeout, final TimeUnit unit, final boolean returnOnTimeout, final ReceiveMessageHandler handler
|
||||
final long timeout, final TimeUnit unit, final ReceiveMessageHandler handler
|
||||
) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue