mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
Unsubscribe receive if jsonRpcSender channel is closed
This commit is contained in:
parent
7bf06aef5e
commit
c8cd36bde8
2 changed files with 11 additions and 2 deletions
|
@ -30,6 +30,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.OverlappingFileLockException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -101,7 +102,14 @@ public class SignalJsonRpcDispatcherHandler {
|
|||
final var receiveMessageHandler = new JsonReceiveMessageHandler(m, s -> {
|
||||
final ContainerNode<?> params = objectMapper.valueToTree(s);
|
||||
((ObjectNode) params).set("subscription", IntNode.valueOf(subscriptionId));
|
||||
jsonRpcSender.sendRequest(JsonRpcRequest.forNotification("receive", params, null));
|
||||
final var jsonRpcRequest = JsonRpcRequest.forNotification("receive", params, null);
|
||||
try {
|
||||
jsonRpcSender.sendRequest(jsonRpcRequest);
|
||||
} catch (AssertionError e) {
|
||||
if (e.getCause() instanceof ClosedChannelException) {
|
||||
unsubscribeReceive(subscriptionId);
|
||||
}
|
||||
}
|
||||
});
|
||||
m.addReceiveHandler(receiveMessageHandler);
|
||||
return new Pair<>(m, (Manager.ReceiveMessageHandler) receiveMessageHandler);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue