mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Add setIgnoreAttachments method
This commit is contained in:
parent
3636023cb8
commit
f5ba7894ae
6 changed files with 32 additions and 33 deletions
|
@ -194,13 +194,11 @@ public interface Manager extends Closeable {
|
||||||
void requestAllSyncData() throws IOException;
|
void requestAllSyncData() throws IOException;
|
||||||
|
|
||||||
void receiveMessages(
|
void receiveMessages(
|
||||||
long timeout,
|
long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
|
||||||
TimeUnit unit,
|
|
||||||
boolean returnOnTimeout,
|
|
||||||
boolean ignoreAttachments,
|
|
||||||
ReceiveMessageHandler handler
|
|
||||||
) throws IOException;
|
) throws IOException;
|
||||||
|
|
||||||
|
void setIgnoreAttachments(boolean ignoreAttachments);
|
||||||
|
|
||||||
boolean hasCaughtUpWithOldMessages();
|
boolean hasCaughtUpWithOldMessages();
|
||||||
|
|
||||||
boolean isContactBlocked(RecipientIdentifier.Single recipient);
|
boolean isContactBlocked(RecipientIdentifier.Single recipient);
|
||||||
|
|
|
@ -135,6 +135,7 @@ public class ManagerImpl implements Manager {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private boolean hasCaughtUpWithOldMessages = false;
|
private boolean hasCaughtUpWithOldMessages = false;
|
||||||
|
private boolean ignoreAttachments = false;
|
||||||
|
|
||||||
ManagerImpl(
|
ManagerImpl(
|
||||||
SignalAccount account,
|
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<>();
|
Set<HandleAction> queuedActions = new HashSet<>();
|
||||||
for (var cachedMessage : account.getMessageCache().getCachedMessages()) {
|
for (var cachedMessage : account.getMessageCache().getCachedMessages()) {
|
||||||
var actions = retryFailedReceivedMessage(handler, ignoreAttachments, cachedMessage);
|
var actions = retryFailedReceivedMessage(handler, cachedMessage);
|
||||||
if (actions != null) {
|
if (actions != null) {
|
||||||
queuedActions.addAll(actions);
|
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();
|
var envelope = cachedMessage.loadEnvelope();
|
||||||
if (envelope == null) {
|
if (envelope == null) {
|
||||||
|
@ -873,13 +874,9 @@ public class ManagerImpl implements Manager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveMessages(
|
public void receiveMessages(
|
||||||
long timeout,
|
long timeout, TimeUnit unit, boolean returnOnTimeout, ReceiveMessageHandler handler
|
||||||
TimeUnit unit,
|
|
||||||
boolean returnOnTimeout,
|
|
||||||
boolean ignoreAttachments,
|
|
||||||
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
|
@Override
|
||||||
public boolean hasCaughtUpWithOldMessages() {
|
public boolean hasCaughtUpWithOldMessages() {
|
||||||
return hasCaughtUpWithOldMessages;
|
return hasCaughtUpWithOldMessages;
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class DaemonCommand implements MultiLocalCommand {
|
||||||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||||
) throws CommandException {
|
) throws CommandException {
|
||||||
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
||||||
|
m.setIgnoreAttachments(ignoreAttachments);
|
||||||
|
|
||||||
DBusConnection.DBusBusType busType;
|
DBusConnection.DBusBusType busType;
|
||||||
if (Boolean.TRUE.equals(ns.getBoolean("system"))) {
|
if (Boolean.TRUE.equals(ns.getBoolean("system"))) {
|
||||||
|
@ -65,7 +66,7 @@ public class DaemonCommand implements MultiLocalCommand {
|
||||||
|
|
||||||
try (var conn = DBusConnection.getConnection(busType)) {
|
try (var conn = DBusConnection.getConnection(busType)) {
|
||||||
var objectPath = DbusConfig.getObjectPath();
|
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)) {
|
try (var conn = DBusConnection.getConnection(busType)) {
|
||||||
final var signalControl = new DbusSignalControlImpl(c, m -> {
|
final var signalControl = new DbusSignalControlImpl(c, m -> {
|
||||||
|
m.setIgnoreAttachments(ignoreAttachments);
|
||||||
try {
|
try {
|
||||||
final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber());
|
final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber());
|
||||||
return run(conn, objectPath, m, outputWriter, ignoreAttachments);
|
return run(conn, objectPath, m, outputWriter);
|
||||||
} catch (DBusException e) {
|
} catch (DBusException e) {
|
||||||
logger.error("Failed to export object", e);
|
logger.error("Failed to export object", e);
|
||||||
return null;
|
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 {
|
) throws DBusException {
|
||||||
final var signal = new DbusSignalImpl(m, conn, objectPath);
|
final var signal = new DbusSignalImpl(m, conn, objectPath);
|
||||||
conn.exportObject(signal);
|
conn.exportObject(signal);
|
||||||
|
@ -133,7 +135,7 @@ public class DaemonCommand implements MultiLocalCommand {
|
||||||
final var receiveMessageHandler = outputWriter instanceof JsonWriter
|
final var receiveMessageHandler = outputWriter instanceof JsonWriter
|
||||||
? new JsonDbusReceiveMessageHandler(m, (JsonWriter) outputWriter, conn, objectPath)
|
? new JsonDbusReceiveMessageHandler(m, (JsonWriter) outputWriter, conn, objectPath)
|
||||||
: new DbusReceiveMessageHandler(m, (PlainTextWriter) 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;
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("Receiving messages failed, retrying", e);
|
logger.warn("Receiving messages failed, retrying", e);
|
||||||
|
|
|
@ -66,6 +66,7 @@ public class JsonRpcDispatcherCommand implements LocalCommand {
|
||||||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||||
) throws CommandException {
|
) throws CommandException {
|
||||||
final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
final boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
||||||
|
m.setIgnoreAttachments(ignoreAttachments);
|
||||||
|
|
||||||
final var objectMapper = Util.createJsonObjectMapper();
|
final var objectMapper = Util.createJsonObjectMapper();
|
||||||
final var jsonRpcSender = new JsonRpcSender((JsonWriter) outputWriter);
|
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(
|
final var receiveThread = receiveMessages(s -> jsonRpcSender.sendRequest(JsonRpcRequest.forNotification(
|
||||||
"receive",
|
"receive",
|
||||||
objectMapper.valueToTree(s),
|
objectMapper.valueToTree(s),
|
||||||
null)), m, ignoreAttachments);
|
null)), m);
|
||||||
|
|
||||||
// Maybe this should be handled inside the Manager
|
// Maybe this should be handled inside the Manager
|
||||||
while (!m.hasCaughtUpWithOldMessages()) {
|
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(
|
private Thread receiveMessages(JsonWriter jsonWriter, Manager m) {
|
||||||
JsonWriter jsonWriter, Manager m, boolean ignoreAttachments
|
|
||||||
) {
|
|
||||||
final var thread = new Thread(() -> {
|
final var thread = new Thread(() -> {
|
||||||
while (!Thread.interrupted()) {
|
while (!Thread.interrupted()) {
|
||||||
try {
|
try {
|
||||||
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, jsonWriter);
|
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, jsonWriter);
|
||||||
m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, receiveMessageHandler);
|
m.receiveMessages(1, TimeUnit.HOURS, false, receiveMessageHandler);
|
||||||
break;
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn("Receiving messages failed, retrying", e);
|
logger.warn("Receiving messages failed, retrying", e);
|
||||||
|
|
|
@ -148,14 +148,11 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
|
||||||
timeout = 3600;
|
timeout = 3600;
|
||||||
}
|
}
|
||||||
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
boolean ignoreAttachments = Boolean.TRUE.equals(ns.getBoolean("ignore-attachments"));
|
||||||
|
m.setIgnoreAttachments(ignoreAttachments);
|
||||||
try {
|
try {
|
||||||
final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
|
final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
|
||||||
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
|
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
|
||||||
m.receiveMessages((long) (timeout * 1000),
|
m.receiveMessages((long) (timeout * 1000), TimeUnit.MILLISECONDS, returnOnTimeout, handler);
|
||||||
TimeUnit.MILLISECONDS,
|
|
||||||
returnOnTimeout,
|
|
||||||
ignoreAttachments,
|
|
||||||
handler);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
|
throw new IOErrorException("Error while receiving messages: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,15 +425,16 @@ public class DbusManagerImpl implements Manager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveMessages(
|
public void receiveMessages(
|
||||||
final long timeout,
|
final long timeout, final TimeUnit unit, final boolean returnOnTimeout, final ReceiveMessageHandler handler
|
||||||
final TimeUnit unit,
|
|
||||||
final boolean returnOnTimeout,
|
|
||||||
final boolean ignoreAttachments,
|
|
||||||
final ReceiveMessageHandler handler
|
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIgnoreAttachments(final boolean ignoreAttachments) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCaughtUpWithOldMessages() {
|
public boolean hasCaughtUpWithOldMessages() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue